I use JsonBuilder to build a JSONObject/String.
But, how can I update/change value of one field in this JSONObject/String?
I am not seeing the possibility of doing this using JsonBuilder. What show I use then?
I use JsonBuilder to build a JSONObject/String.
But, how can I update/change value of one field in this JSONObject/String?
I am not seeing the possibility of doing this using JsonBuilder. What show I use then?
If you have to change the content you already put into the JsonBuilder, then you could do:
But as
content
is not explicitly exported from the Object, I'd call this a side-effect and would not rely on it working in future versions of Groovy.Better to get your map right before you pass it to
JsonBuilder
, or if that isn't possible I guess you'll need to parse the Json string withJsonSlurper
modify the resulting Map and then rebuild the Json withJsonBuilder
again.