0

I have problem with my SoapUI Groovy script. I have following json (simplified):

{  
"data":{  
  "XXX":[...]
  "YYY":[...]

},
"next":"ffawef234fava23r"
}

I have values of XXX and YYY in my previously TestStep as request parameters and I extract it properly as list of string, but my problem is that I need to extract content of data.XXX and data.YYY, but when I want to do this in loop I always get null. My code:

def content = new JsonSlurper().parseText(response)
def ids = extracted_ids.split(';')     //List of IDs in response above {XXX,YYY}
for (id in ids){
                    log.info id // XXX
                    log.info content.data.'XXX'   //this works 
                    log.info content.data.id      //this not
}

Is there any option to pass this "id" in loop to content.data.{id} to get any content instead of null

Kind Regards

jadupl
  • 210
  • 6
  • 17
  • Would you mind showing complete structure of json and mention specific data that needs to be extracted? – Rao Apr 26 '17 at 16:15
  • I have simplified output to better reading. In fact I just need to check If data.XXX and data.YYY is null or not – jadupl Apr 26 '17 at 16:28
  • You do not have to put you exact data if that is sensitive. Just put the structure with replacing dummy keys and value. Because, solution may vary based on the data. Hope you understand. – Rao Apr 26 '17 at 17:05

1 Answers1

1

You just need to do

log.info content.data."$id"
tim_yates
  • 167,322
  • 27
  • 342
  • 338