Forum Discussion
- StevenColon
Alumni
Thank you for posting to our Community Forum.
There is currently no way to sort a JSON response through the REST Request teststep.
The best way to do this currently is to write a script in a groovy script test step after the request and use JSlurper to sort the information.
Here is an example script (created in ReadyAPI 2.1) that gets the response data, parses it with JSlurper, and sorts it.
def response = context.expand( '${GET Request#Response}' )
//Property Expansion Format: '${<TESTSTEP>#Response}' def slurper = new groovy.json.JsonSlurper() def result = slurper.parseText(response) //Prints out JSON sorted alphabetically by key log.info result.sort()
You can then put that value into a property so that other test steps can use it. Here is the code line to do that:testRunner.getTestCase().setPropertyValue("sortedJSON", result.toString())
Let me know if you have any questions/concerns.
- nmrao
Champion Level 2
Can you explain the question with a sample data?