Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

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 -
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.



  • williammccusker
    williammccusker Posts: 622 ✭✭✭


    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.