Traversing through json elements using JsonOutput
Requirement: I need to read a json from a file, traverse through the JSON elements and modify multiple values.
I am using JsonSlurper to parse the text and traverse through the elements and able to modify the values. My request json contains multiple json arrays and json objects and elements.
Issue: I have 2 unique environments. It's working fine in one environment and but in other environment I get the response output in alphabetical order.
Because jsonSlurper does not guarantee the output order - https://stackoverflow.com/questions/33018236/how-to-maintain-jsons-order-in-groovys-jsonslurper
Question 1: Is there a way to maintain the json response order same as the input json order?
I can't use LinkedHashMaps or any other ordered map/list, because my json contains json arrays and I am not able to traverse though the elements after that.
Question 2: Is there a way to traversing through json elements using JsonOutput?. JsonOutput.toJson(jsonString) returns String.
Comments
-
Hi,
I am not completely familiar the groovy json library. If it is not working have you considered using Javascript instead? That scripting language will have json parsing and its behavior may be different than what you are seeing in Groovy.
0