How to ignore a Specific field in pm.expect

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"

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.


Hey @sriramku,

Welcome to the community! :wave:

As it’s an object, it might be worth taking a look at using the delete method.

An example from that link would be:

const Employee = {
  firstname: 'John',
  lastname: 'Doe'

// expected output: "John"

delete Employee.firstname;

// expected output: undefined

So for your case, you could use:

delete pm.response.json().userId; 
delete pm.response.json().dateCreated;