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);
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
I have built a sample one in my public workspace, please check this for more details.
@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