How to ignore a specific field in pm.expect irrespective of its level and occurances

Our API response has fields like timestamp, GUID’s etc which I would like to exclude from the comparison in pm.expect.

How can we exclude a field completely from the comparison in expect like in my case the response looks like.

{
“userId”: “This is a random Guid”,
“dateCreated”: “This is a dynamic timestamp”,
“firstName” : “Test”,
“person”:{
“firstName”:“test1”
}
}

So in this data, I would like to compare my whole response JSON with an expected JSON(which I have in a separate variable).
I can compare this using pm.expect(actualJSON).to.eql(expectedJSON);

Just that i want to ignore specific fields.

Pls suggest a way to do this.

Hi @Akram_Shaik,

One way I could think of is, to remove those key-value pairs from the response output and expected output which you don’t want to compare.

Once you have the JSON data in the expected format, you can use expect to compare.

Hi @Akram_Shaik , Yes as @pranavdavar suggested you build your expected response.

Please check if this pick method helps you. This will help you to pick the expected attributes to be listed, and you can store that as a expected response to proceed further :blush:

I have built a sample one in my public workspace, please check this for more details.

https://www.postman.com/bpricilla/workspace/pricilla-s-api-space/request/12539800-50968829-5cf3-4f6c-be50-2320517f9fed

Please let me know if there’s any other doubts :slightly_smiling_face:

@pranavdavar thanks for your response. But it json is too large and there are too many values which needs to be excluded then its going be a very large script and also difficult to maintain. I am trying to find is there any function which ignore/delete the property irrespective of level. So that i don’t to specifiy entire structure of the property(Ex: person.firstName), instead just pass (firstName)

@bpricilla thanks for your suggestion that really helps.
Actually i am looking to compare two big json responses using pm.expect. if there is any difference in the values in then it should fail.

For example
Response1:
{
“userId”: “This is a random Guid”,
“dateCreated”: “This is a dynamic timestamp”,
“firstName” : “Test”,
“person”:{
“firstName”:“test1”
}
}

Resposne-2:
{
“userId”: “This is a random Guid”,
“dateCreated”: “This is a dynamic timestamp”,
“firstName” : “Test1”,
“person”:{
“firstName”:“test”
}
}

the above responses should be compared by excluding firstName property