Hello! I am trying to validate the field “value” for each person in this list by using a test like:
bodyData = JSON.parse(responseBody)
response1 = bodyData.list[0].value
pm.test(“Verify this is the original record”, function () {
pm.expect(response1).to.eql(“Original”);
});
response2 = bodyData.list[1].value
pm.test(“Verify this is the new record”, function () {
pm.expect(response2).to.eql(“New”);
});
I have a JSON response body like this:
{
“id”: 3199,
“list”: [
{
“person_id”: 3817,
“value”: “Original”
},
{
“person_id”: 3818,
“value”: “New”,
}
]
}
This seems to work just fine most of the time… BUT
sometimes the JSON body reads differently, and the person_id’s are FLIPPED!
i.e.
{
“id”: 3199,
“list”: [
{
“person_id”: 3818,
“value”: “New”,
},
{
“person_id”: 3817,
“value”: “Original”
}
]
}
This fails my test. I am sure there is a simple workaround for this, but it is escaping me at the moment.
Is there any way to either A. organize the list in the payload so that is dependably in the same position JSON path? I am wondering the best route for this one. Thanks!