Forum Discussion

neha2's avatar
neha2
Regular Visitor
3 years ago

Groovy - context.expand with condition in json response groovy

i am trying to do context.expand to fetch a response in JSON,  having a particular value for one of the attributes, not able to achieve , i have tried using .each, find() etc . 

I want to count instances of "countryDetails" where address type = primary only

Solution tried so far 

String AddressType =context.expand( '${Response#$[\'countryDetails\'][*][\'addressType\'}')

it give me values like - address type =[primary, secondry,secondry, primary]

but i only want where address type = primary, so it should be 

address type =[primary,primary,primary]

and then i would use it for further validations. 

 

 

example json :

 

"countryDetails": {
"link": [],
"firstRecord": 1,
"pageSize": 1000,
"searchToken": "multi",
"item": [
{
"Id": "13680007 ",
"label": "Address",
"addressType": " Primary ",
"CountryCode": {
"Code": "IN",
"status": "ACTIVE",
"countryEnglishName": "INDIA"
}
}
]
}
}
]
},

No RepliesBe the first to reply