I have this JSON that returns from the REST service that I use.
{ "id": "6804", "signatories": [ { "id": "12125", "fields": [ { "type": "standard", "name": "fstname", "value": "John" }, { "type": "standard", "name": "sndname", "value": "Doe" }, { "type": "standard", "name": "email", "value": " john.doe@somwhere.com " }, { "type": "standard", "name": "sigco", "value": "Company" } ] } ] }
I'm currently exploring a way to parse this with json4s, iterating over the fields array to be able to change the value property of various objects. So far I have tried several json libs and ended up with json4s .
Json4s allows me to parse json in a JObject, which I can try to extract an array of "fields" from.
import org.json4s._ import org.json4s.native.JsonMethods._
I managed to extract such a Map and return it to JSON again. However, I canโt understand how to lay these fields and change the โvalueโ value in them?
I read the json4s documentation, but I'm very new to both Scala and syntax, so I have a hard time.
The question is, how do I iterate over the result of a JSON analysis to change the value of a property?
Here is the flow that I want to achieve.
- Parsing JSON into an iterable object
- Scroll and find the specific โnamesโ and change their meaning, for example fstname, from John to another name.
- Parse it back to JSON so that I can send a new JSON with updated values.
I donโt know if this is really the best way to do this, I would really appreciate input, maybe there is an easier way to do this.
Thanks in advance, Best regards,
Stefan Conno