I tried converting Map[String, Map[String, Any]] in Scala to JSON but since they have nested maps so unable to do it. Is there a way to do it? I tried looking at this link but it converts everything to string and converts a list as "List(...)". Any ideas how to go about this? I am even fine with solutions of Map[String, Map[String, String]].
Asked
Active
Viewed 1,753 times
0
-
1You can have a look at http://json4s.org/ – Louis F. Jul 12 '16 at 13:45
-
Why do you have `Any`? – cchantep Jul 12 '16 at 13:48
2 Answers
1
You can use play-json library. Then converting nested maps would look like this:
import play.api.libs.json.{JsValue, Json}
val nestedMap: Map[String, Map[String, String]] = Map("employees" -> Map("Paul" -> "developer", "Alice" -> "accountant"))
val json: JsValue = Json.toJson(nestedMap)
val compactJson: String = Json.stringify(json)
println(compactJson)
Output:
{"employees":{"Paul":"developer","Alice":"accountant"}}

Paweł Jurczenko
- 4,431
- 2
- 20
- 24
-
Thanks. I also saw that one can do compact(render(decompose(nestedMap))). Here I am talking about the netliftweb.json library. – Meet Vadera Jul 19 '16 at 16:22
0
Thanks. I also saw that one can do compact(render(decompose(nestedMap))). Here I am talking about the netliftweb.json library

Meet Vadera
- 1
- 2