# Assert two JSON objects

**URL:** <https://community.postman.com/t/assert-two-json-objects/7879>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [September 19, 2019, 6:10am UTC](https://community.postman.com/t/assert-two-json-objects/7879 "2019-09-19T06:10:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![himanshudwivedi1989](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@himanshudwivedi1989](https://community.postman.com/u/himanshudwivedi1989)\
**Post date:** [September 19, 2019, 6:10am UTC](https://community.postman.com/t/assert-two-json-objects/7879/1 "2019-09-19T06:10:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [September 19, 2019, 6:59am UTC](https://community.postman.com/t/assert-two-json-objects/7879/2 "2019-09-19T06:59:22Z")

</div>

Hello @himanshudwivedi1989, welcome to the community! 👋

You can use `to.eql` and write the following:

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

```

---

<div class="post-metadata">

**Author:** ![himanshudwivedi1989](https://avatars.discourse-cdn.com/v4/letter/h/4bbf92/32.png) [@himanshudwivedi1989](https://community.postman.com/u/himanshudwivedi1989)\
**Post date:** [September 20, 2019, 6:27am UTC](https://community.postman.com/t/assert-two-json-objects/7879/3 "2019-09-20T06:27:54Z")

</div>

Hi Siv  
thanks for the quick help.

---

<div class="post-metadata">

**Author:** ![nishant.shah2](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@nishant.shah2](https://community.postman.com/u/nishant.shah2)\
**Post date:** [May 20, 2020, 11:36am UTC](https://community.postman.com/t/assert-two-json-objects/7879/4 "2020-05-20T11:36:18Z")

</div>

Hi,  
This is somehow not working for me.  
In case:-  
var expectedObject = {  
“id”:“doe”,  
“name”:“john”  
}  
i.e. the order of the fields inside the json structure changes then the assertion fails.  
If its actually a JSON object comparision then it should not fail.  
Anyway, this can be achieved?

---

<div class="post-metadata">

**Author:** ![lowcrawler](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@lowcrawler](https://community.postman.com/u/lowcrawler)\
**Post date:** [March 20, 2022, 2:59pm UTC](https://community.postman.com/t/assert-two-json-objects/7879/5 "2022-03-20T14:59:25Z")

</div>

Any solution found to the key re-order problem?
