Need to help in automating the json response which doesnot contains array

Hi ,

I am trying to fetech the data from the postman which is not present as array. Can you please help me with the same.

I need to validate whether mealcode is present or not in ST2 & ST1

Please help me with the same

“ABC”: {
“B”: {
“ST2”: {
“meals”: {
“bookingClass”: “R”,
“mealCodes”: [
“H”,
“H”
]
}
},
“ST1”: {
“meals”: {
“bookingClass”: “R”,
“mealCodes”: [
“H”,
“H”
]
}
}
}

Hi @prashanthpatil, will the response structure be the same?
Or is it subject to change?

Also, you need to test if mealCodes property exists and the type is that of an array, correct?

@prashanthpatil Do you need to simply validate that each of ST1 and ST2 have the mealCodes object in the response or do you need to validate the content in those objects?

You could do come sort of JSON validation like this …

pm.test("Validate Response Body Is Correct", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.ABC.B.ST2.meals.mealCodes()).to.include("H");
    pm.expect(jsonData.ABC.B.ST1.meals.mealCodes()).to.include("H");
}); 

Or something along those lines maybe?