How to get all parameter Values from RestAPI response in an arrayList using Java/Groovy
My response api like this in ReadyAPI tool-
{
"response" : [
{
"imageid" : "asdfg1234",
"softwareId" : 282046477,
"accessLevel" : "register",
},
{"imageid" : "asdfg1235",
"softwareId" : 282046478,
"accessLevel" : "not-register",
},
{
"imageid" : "asdfg1236",
"softwareId" : 282046479,
"accessLevel" : "register",
},
}
I want to store all the values in an arrylist like-
[ "asdfg1234",282046477,"register","asdfg1235"282046478, "not-register","asdfg1236",282046479,"register"]
I tried this code - but getting null response
ArrayList<String> resArrayList = new ArrayList<String>()
for( int i = 0; i < 10; i++)
{
def resimageid = context.expand( '${RestAPI#Response#$[\'response\'][i][\'imageid\']}' )
def ressoftwareId = context.expand( '${RestAPI#Response#$[\'response\'][i][\'softwareId\']}' )
def resaccessLevel = context.expand( '${RestAPI#Response#$[\'response\'][i][\'accessLevel\']}' )
resArrayList.add(resimageid)
resArrayList.add(ressoftwareId)
resArrayList.add(resaccessLevel)
}
log.info(resArrayList)
Please Help me to get the values.
manisha1 :
So, i don't think that will be any change as mongo will return JSON and in Rest response you will be getting json.
So use JsonSlurper and match node by node.