Hello,
I am new to Postman. My issue is described below. Kindly suggest.
Hit a request, select one JSON variable/property from Response, if that value is > 10, fail the assertion in Tests.
When I am trying to save the JSON property, it’s replying back saying it’s Undefined.
I tried parsing too but didn’t work. Also, I tried the below code which didnt work.
pm.test(“Max Temp greater than 10 validation”,function () {
var jsonData = pm.response.json();
pm.expect(jsonData.temp_max).tobeLessthan(10);
});
Hey @ArupAcharya
Welcome to the Postman community! 
Could you share an example of the response body, please?
Without seeing the response I’m just guessing here but it could be something like this:
pm.expect(jsonData["temp_max"]).to.be.below(10);
Thanks @danny-dainton. here is the response.
{
"coord": {
"lon": -74.01,
"lat": 40.71
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 295.74,
"feels_like": 294.5,
"temp_min": 294.26,
"temp_max": 297.15,
"pressure": 1028,
"humidity": 36
},
"visibility": 10000,
"wind": {
"speed": 0.69,
"deg": 216
},
"clouds": {
"all": 1
},
"dt": 1604870456,
"sys": {
"type": 1,
"id": 4610,
"country": "US",
"sunrise": 1604835312,
"sunset": 1604871871
},
"timezone": -18000,
"id": 5128581,
"name": "New York",
"cod": 200
}
@danny-dainton
It still fails with below error.
Max Temp greater than 10 validation | AssertionError: expected undefined to be a number or a date
It looks like temp_max
is inside the main
object so it would be jsonData.main["temp_max"]
It works like a mule.
Thanks very much. Appreciate your quick response. Learnt something tonight. happy to sleep now.
1 Like