Suppose I have a json array that looks like this (I receive it from a remote service):
[{"id": 1}, {"id": 2}, ... , {"id": 10}]
And, say, I want to 'transform' it like this (add 100 to 'id's and other values):
[{"id": 101}, {"id": 102}, ..., {"id": 110} ]
As for starters I wanted to 'update' it so that it would at least replace the initial array with a blank one (just to test how stuff works).
Json.parse("""[{"id": 1}, {"id": 2}]""").transform( (__).json.update( __.read[JsArray].map(_ => JsArray()) ))
But it throws an exception:
play.api.libs.json.JsResult[play.api.libs.json.JsObject] = JsError(List((,List(ValidationError(List(error.expected.jsobject),WrappedArray())))))
However if they are sealed inside of a json object then it kinda works:
Json.parse("""{"ids": [{"id": 1}, {"id": 2}]}""").transform( (__ \ "ids").json.update( __.read[JsArray].map(_ => JsArray()) ))
which results in
play.api.libs.json.JsResult[play.api.libs.json.JsObject] = JsSuccess({"ids":[]},/ids)
How do I deal with array json? Thanks in advance