I have a use case where I need to verify a key in an object based on another key in the same object,
{
"status": "success",
"version": "2.0",
"data": [
{
"key1": 4,
"key2": "100"
}, {
"key1": 2,
"key2": "200"
}
]
}
Here I want to assert key 1 = 4 /2 if key 2 is 100 /200
@danny-dainton Please help
Hey @swasthik08
What have you tried so far? What’s failing for you?
var jsonData = pm.response.json();
const key2 = jsonData.data.find(u => u.key2 === '100')
const key1 = key2 ? key2.metric : 'not found'
pm.test("Verify Analysis shown is correct", function () {
var jsonData = pm.response.json();
pm.expect(key2.metric).to.eql(4);
I tried this and it worked but As I have to assert many keys and many objects …is there any better /optimized scripts to reuse it for each objects in array