Forum Discussion
nila2020
7 years agoNew Contributor
I am new to groovy script, Please can you explain what is [b:2,a:1], Thank you in advance
JHunt
7 years agoCommunity Hero
That's a Map. It's just like an object in JSON. So for parsing a response, and checking the keys of the object, you would do something like this:
String response = '''{
"DataValue": [
{
"ABC1": "Value",
"ABC2": "Value"
}, {
"ABC1": "Value",
"ABC2": "Value"
}
]
}'''
new groovy.json.JsonSlurper().parseText(response)["DataValue"].each { dataValue ->
ArrayList<String> keys = dataValue.collect { key, value -> key }
assert keys == [ "ABC1", "ABC2" ]
}
And the assertion will fail if the order is different to what you are expecting.
- nila20207 years agoNew Contributor
Thank you for your response, Appreciate your help