Validate Jason Array using ID

Here is my json and getting the names as json array which means every time the json path changing and test case keep failing if i use verifyelementpropertyvalue.
let me know how do i validate the value based on id if the json path is dynamic ?

“data”:{
“names”:[
{
“id”:1123,
“nameID”:“Test123”,
“required”:false,
“ancillary”:true,
“autoGenerate”:true
},
{
“id”:1203,
“nameID”:“Test124”,
“required”:false,
“ancillary”:true,
“autoGenerate”:false
},
{
“id”:1120,
“nameID”:“Test125”,
“required”:true,
“ancillary”:true,
“autoGenerate”:false
},
{
“id”:1124,
“nameID”:“Test234”,
“required”:false,
“ancillary”:true,
“autoGenerate”:true
},
]
}

use json schema validation, there are few discussion on this matter on the forum
or, if you have to validate the value of a key based on other, or a known index, write a keyword to traverse the json programatical
e.g, use json.slurper to convert the response to a map and you can traverse all objects in ‘names’ using response.data.names.each

sorry for not posting a sample code, typing from the phone but i hope you can figure it out

1 Like