I am new to Scala and I want to build an object that looks like below and then convert to Json, but doing something like this gives me error. How can I achieve this?
This is what I tried:
Map(a -> Map(b-> "1", c -> "2"),
Map(d -> values.map(v => Map(b-> v.value1, c -> v.value2)))
.asJson
Expected outcome:
{
"a":{"b": "1", "c": "2"},
"d":[{"b":"x1","c":"x2"},{"b":x3,"c":"x4"}...]
}
Json, or if this is something used in a single place then you may indeed consider using theJsontype provided by your library rather than using an heterogeneous map.Jsonobject, just like the accepted answer shows how to do it using circe.