Check Response body contains Match value

I am new to postman
My Response Body is like something i want to check first name is match or not ?
can anyone help ?

{

"status": true,

"status_code": 200,

"data": {

    "first_name": {

        "result": "Match"

    },

    "middle_name": {

        "result": "No Match"

    },

    "last_name": {

        "result": "Match"

    },

    "dob": {

        "result": "No Match"

    },

    "city": {

        "result": "Match"

    },

    "zip": {

        "result": "No Match"

    },

    "state": {

        "result": "No Match"

    },

    "address": {

        "result": "Match"

    },

    "gender": {

        "result": "No Match"

    },

    "phone": {

        "result": "No Match"

    },

    "email": {

        "result": "No Match"

    }

},

"transaction_id": "15961139575f22c42541d3ahp2Qw",

"request_id": "00001"

}

1 Like

Welcome @Bhaumik!

In the tests tab of your request, you’re going to want to add the following code:

pm.test("First name matches", function () {
   var jsonData = pm.response.json();
   pm.expect(jsonData.data.first_name).have.property('result', 'Match');
});

image
All you’re doing here is just checking if a json value equals something, so it’s a pretty easy test to write.

You can also use the little test script snippets on the right hand side of the tests panel to get you started for things like this in the future.
image

2 Likes

@allen.helton Thanks a lot.

1 Like

Can we do something similar with an XML response? My use case uses XML rather than JSON.

I would like to capture my sessionid value when the STATUS is 200.

200

You could probably use the same script @odanylewycz mentioned in this post:

1 Like

Hi @dyom,

Welcome to the community! :clap:

You certainly can do XML parsing in postman. As @allen.helton referred to my post, you can use cheerio.js.

I made a video that covers it pretty well. It also links to the code you can copy and use for your use case. Take a look here:

Hope it helps!