KSN
8 years agoNew Contributor
How to get the property from Json response using Groovy in soapui
Hi ,
Below is the json response, from this i need to get the uri based on the name, here name=abc.
Using json.url[0].services[0].config.www[0].uri, i got the desired value but heard that its not the proper way to handle.
Please help me how to get this through groovy script. Thanks in advance.
{
"url": [
{
"name": "test",
"services": [
{
"name": "abc",
"config": {
"www": [
{
"scheme": "https",
"uri": "https://abc.com"
}
]
}
},
{
"name": "def",
"config": {
"www": [
{
"scheme": "https",
"uri": "https://def.com"
}
]
}
}
]
},
{
"name": "test1",
"services": [
{
"name": "abc",
"config": {
"www": [
{
"scheme": "https",
"uri": "https://abc.com"
}
]
}
},
{
"name": "def",
"config": {
"www": [
{
"scheme": "https",
"uri": "https://def.com"
}
]
}
}
]
}
]
}Regards,
Raj
I would do something like this...
new groovy.json.JsonSlurper().parseText(json) .url.find { it.name == 'test' } .services.find { it.name == 'abc' } .config.www.uri