Using Postman to compare the content of a JSON return with a known/expected JSON/data

Hi,

Hopefully someone can point me in the right direction.

I am a test analyst with some exposure to manual testing of API’s but very limited javascript knowledge (I mostly do functional testing).

We want to use Postman to automate API testing for a new project. Grasped the basics of how to test response codes (200 ok, 404 etc) but is it possible to do the following…

Send a GET request, (which will return a JSON with around 100 lines) and compare the content of that JSON with a JSON that we already have. Example of part of the JSON below.

I guess in simple terms: I want to check that the GET returns the correct name, address etc. Eventually we will have JSON responses that will contain hundreds of data items so keen to avoid having to manually check them all…

Apologies if this is a bit vague.

“policyholder”: {
“title”: “Mr”,
“forename”: “TEST”,
“surname”: “TEST”,
“dateOfBirth”: “1980-01-01”,
“address1”: “1 TEST ROAD”,
“address2”: “TESTTOWN”,
“address3”: “TESTCOUNTY”,
“address4”: “”,
“postcode1”: “AA12”,
“postcode2”: “9AA”,
“email”: “MADEUP@TEST.COM”,
“homeTel”: “01234567890”,
“workTel”: "12345 678901 "
},

Solved.

pm.test(“title is correct”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.policy.policyholder.title).to.eql(“Mr”);
});

Repeat for each one.

1 Like