Postman: How to check whether the field is returning null in the Postman automation

I have tried with !== null, but it is returning PASS even when the field is returning 0 or empty string.

This works as of Mar-2019:

pm.test("To Check if Value is Null", function() {
var jsonData = pm.response.json();

Did you try



If you are checking the Id of the first item returned in a list, you could use not.equal(null):


Note that the word “equal” is fully spelled out, although the shortened “eql” does work.

try this one:

pm.test("your-value is not null", function () {
var jsonData = pm.response.json();

Postman doesn’t reference non-existent paths as null, but as undefined.


This test should fail, as this fake json path is actually undefined.

I faced similar issue. But checking it in following way worked for me

tests["Item is not null"] = 
    jsonData.item !== undefined;

You can access response json like :

    var json = JSON.parse(responseBody);
    var yourVAr = json.yourVar
    if(yourVar == null){
        //your var is null here

I have done similar, this is one part of the code and its works well
Check this code

var jsonData = JSON.parse(responseBody);

for(i=0; i<; i++){
tests["due date is between given date range"] =[i].duedate < environment.Cenddate &&[i].duedate > environment.Cstartdate;

tests["response body has department name"] =[i] !== null;


How about:

var jsonData = JSON.parse(responseBody);

tests["Item is not null"] = 
    jsonData.item !== null && 
    jsonData.item !== ' ' && 
    jsonData.item !== 0;

You gotta place the + [i] after the function you gonna validate on the tests[] so only it will return valid statements on each array. For example,

function checkIsNull() {
    var items =
    var PlaceIdIsNull = true;
    var subTypeExtraIsNull = true;
    var websiteIsNull = true;

    for (var i = 0; i < items.length; i++) {
    if (items[i].placeId !== null) {
        PlaceIdIsNull = false;
    if (items[i].subTypeExtra !== null) {
        subTypeExtraIsNull = false;
    if (items[i].website === null) {
        websiteIsNull = false;
        tests['website is null only happened on these arrays' + [i]] = true;
        tests['Place ID is null '] = PlaceIdIsNull
        tests['subTypeExtra is null '] = subTypeExtraIsNull


PASS Place ID is null

PASS subTypeExtra is null

Try this:

let jsonData = pm.response.json();


This works as at Sept.19, 2022

     pm.test("Check that response body is not null", ()=>{

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Create multiple rows in table from array?

Similar Posts