I need to create a json object, i use play-json lib for Scala.
I have this code:
import play.api.libs.json
import play.api.libs.json._
object Start {
def main(args: Array[String])
{
val GraphDbJson= Json.obj("name"->"father","nodeid"->1,"children"->Json.arr(func1))
println(Json.prettyPrint(GraphDbJson))
}
def func1():JsValue=
{
var JObjChildrenNodes=Seq[JsValue]()
JObjChildrenNodes :+ Json.obj("name"->"child1","nodeid"->2,"children"->Json.arr())
JObjChildrenNodes :+ Json.obj("name"->"child2","nodeid"->3,"children"->Json.arr())
Json.toJson(JObjChildrenNodes)
}
}
and the output is:
{
"name" : "father",
"nodeid" : 1,
"children" : [ [ ] ]
}
how can I pass an json array ? Why the return value of func1 is empty?
Thank you in advance