I am using the Play framework with Scala, and I need to give an input which has to look like so: :
{
id: "node37",
name: "3.7",
data: {},
children:[]
},
How can I obtain that format with json? Here is the example from the Play framework's website:
val JsonObject= Json.obj(
"users" -> Json.arr(
Json.obj(
"id" -> "bob",
"name" -> 31,
"data" -> JsNull,
"children" ->JsNull
),
Json.obj(
"id" -> "kiki",
"name" -> 25,
"data" -> JsNull,
"children" ->JsNull
)
)
)
You may also want to use the Json libraries macros for converting case classes to Json
Then in when you want a Json version of the
MyObject
case class you can just run:And if you have a Controller action that returns json you can wrap it in an Ok result
And the client will see this with the proper Content-Type header as "application/json"
You can find more information about the Json Library and the Macros in the Docs
This is what you need?