Dynamic JSON Creation in Play
I'm trying to dynamically create a JSON object in the following way. Note
that the below code will not compile as I'm requesting your help on how to
code it.
val favoriteFoods: JsArray = getArray() // gets Array of Array of JSON
objects
val json: JsObject = Json.obj(
"name" : JsString("Kevin"),
"FavoriteFood1" -> favoriteFoods.get(0), // note that I made up the get()
"FavoriteFood2" -> favoriteFoods.get(1)
)
Looking at the JsArray docs, I didn't see any way to get the i'th element
of a JsArray.
I tried to add an if statement to check if a new FavoriteFood could be
added, but it would not compile.
No comments:
Post a Comment