I have to store play.api.libs.json.JsValue
keys to a List. How i do this?
var str = ??? //json String
val json: JsValue = Json.parse(str)
val data=json.\("data")
println(data) //[{"3":"4"},{"5":"2"},{"4":"5"},{"2":"3"}]
val newIndexes=List[Long]()
expecting
newIndexes=List(3,5,4,2)
If you want to get all keys in the json you can do it recursively with
Note that the order is not preserved as
values
inJsObject
is aMap
.Another option is to use the
Seq
of fields inJsObject
instead of using thekeys
:This way you will get a breadth-first order of all keys in json object.