Assert two JSON objects

hey i want to assert two JSON objects , can anyone help me in this.

Example:
var jsonData = JSON.stringify(responseBody)

var expectedObject = {
“name” : “john”,
“id” : “doe”
}

Like this i have two JSON objects , one which i have taken from response and another is expected one which i am preparing in my tests script and i want to match these two objects two check whether they are same or not.

Hello @himanshudwivedi1989, welcome to the community! :wave:

You can use to.eql and write the following:

pm.test('Check if objects are equal', function () {
 pm.expect(jsonData).to.eql(expectedObject);
});
3 Likes

Hi Siv
thanks for the quick help.

1 Like