Hi guys need help in validating the json response. I need to validate the json array values and if atleast one value > specific condition my script should pass. below is the json
[
{
"batch_id": xxxxxxx,
"last_revision_id": xxxxxxx,
"priority": "xxxxxxx",
"name": "xxxxxxxx",
"items": 14,
"print_by": "xxxxxxx",
"created": "2xxxxxxx0",
"jsactions": [
{
"label": "xxxxxxx",
"action": "xxxxxxx",
"icon": "xxxxxxxx"
},
{
"label": "xxxxxxx",
"action": "xxxxxx-xxxxx",
"icon": "xxxxxxxx",
}
],
"disappear_date": fgfgh,
"filtered_by_default_tags": fhfghg,
"assignments": 0,
"undeletable_assignments": gggfh
},
{
"batch_id": xxxxxxx,
"last_revision_id": xxxxxxx,
"priority": "xxxxxxx",
"name": "xxxxxxxx",
"items": 5456,
"print_by": "xxxxxxx",
"created": "2xxxxxxx0",
"jsactions": [
{
"label": "xxxxxxx",
"action": "xxxxxxx",
"icon": "xxxxxxxx"
},
{
"label": "xxxxxxx",
"action": "xxxxxx-xxxxx",
"icon": "xxxxxxxx",
}
],
"disappear_date": fgfgh,
"filtered_by_default_tags": fhfghg,
"assignments": 0,
"undeletable_assignments": gggfh
}
]
I used normal if condition using javascript but it is not validating properly
var jsonData = JSON.parse(responseBody);
if (responseBody.has("items")) {
if(jsonData[0].items >=300){
tests["Is atleast one of the batch in future >=300"] = responseBody.has("items");
}
}
else {
tests["The batch is empty"] = responseBody.has("njmkhkhull");
}
But the test getting passed irrespective of the values present in the json array. Even if the json value is 10 if i give the condition as >=30000 it is showing the test as passed.
I used the _.each(pm.response.json(), (arrItem) =>
function it is working fine but this method is not suited for my result analysis as it validates all the array elements.
My desired condition is even if one among the array values satisfies the condition test case should be passed. so that only one value will be logged in console either in case of pass or fail. In case of .each it is logging for all the array values and its cumbersome
please help on this