# Assert portion of JSON with nested objects and arrays

**URL:** <https://community.postman.com/t/assert-portion-of-json-with-nested-objects-and-arrays/6676>\
**Category:** Help Hub\
**Tags:** tests, response\
**Created:** [July 21, 2019, 6:19pm UTC](https://community.postman.com/t/assert-portion-of-json-with-nested-objects-and-arrays/6676 "2019-07-21T18:19:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirbywanner](https://avatars.discourse-cdn.com/v4/letter/k/94ad74/32.png) [@kirbywanner](https://community.postman.com/u/kirbywanner)\
**Post date:** [July 21, 2019, 6:19pm UTC](https://community.postman.com/t/assert-portion-of-json-with-nested-objects-and-arrays/6676/1 "2019-07-21T18:19:22Z")

</div>

Hello

I have an application that uses an API to retrieve data to display to the user in a chart.

I would like to use Postman to ensure the data being returned is consistent over time ( eg value A for July 21, 11:05 pm is the same today as it was originally) as we have had database issues previously.

The data is included in a number of nested objects and comprise just one portion of the API return. I don’t want to compare the entire JSON as there is continuing development on this project that will likely affect some of these other objects and arrays.

I thought there might be some type of JSON.includes function but as of yet cannot find. See screenshot with a portion of the sample JSON with the portion I want to include in the assertion highlighted in yellow.

 ![49%20pm](https://us1.discourse-cdn.com/getpostman/original/2X/d/db19d461cf77c8369f80256e09e4a9cb5ca69014.png)

---

<div class="post-metadata">

**Author:** ![aamir.ahmed](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@aamir.ahmed](https://community.postman.com/u/aamir.ahmed)\
**Post date:** [July 22, 2019, 8:44am UTC](https://community.postman.com/t/assert-portion-of-json-with-nested-objects-and-arrays/6676/2 "2019-07-22T08:44:56Z")

</div>

Hi @kirbywanner,

Welcome to the Postman community! Using the pm library you would be able to check the data and group field in the response against the expected data with the following test script assuming you want to get only the first record from series\_list:

1. pm.test(“check data is expected”, function () {  
var jsonData = pm.response.json();  
pm.expect(jsonData.graph\_options.series\_list[0].data).to.eql(data);  
});
2. pm.test(“check group is expected”, function () {  
var jsonData = pm.response.json();  
pm.expect(jsonData.graph\_options.series\_list[0].group).to.eql(group);  
});

Since series\_list is an array, you will not be able to access just the values in data and group for all the records, you would have to test the series\_list array itself which would be done as given below:  
3. pm.test(“check series list is expected”, function () {  
var jsonData = pm.response.json();  
pm.expect(jsonData.graph\_options.series\_list).to.eql(series\_list);  
});

---

<div class="post-metadata">

**Author:** ![supply-architect-471](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@supply-architect-471](https://community.postman.com/u/supply-architect-471)\
**Post date:** [January 28, 2021, 9:53am UTC](https://community.postman.com/t/assert-portion-of-json-with-nested-objects-and-arrays/6676/3 "2021-01-28T09:53:07Z")

</div>

Halo !  
Thanks for sharing this info… I have difficulty to make tests in Postman to validate the response body has the value I want. For example I want to check 🙂  
response id should be a number  
response name should be a string, etc

I have tried your script but it doesn’t work. Here is my structure data response. Please take a look

{  
“data”: [  
{  
“id”: 114,  
“name”: “tes tanggal repayment”,  
“category”: null,  
“image\_url”: null,  
“tenor”: 18,  
“margin”: 30,  
“margin\_info”: “15% per tahun”,  
“margin\_info\_period”: “6 bulan”,  
“unit\_price”: 15000000,  
“unit\_sold”: 1,  
“unit\_available”: 0,  
“lenders\_count”: 1,  
“fundraising\_info”: “ **1 unit** telah dibiayai oleh **1 orang** , tersisa **0 unit** lagi”,  
“fundraising\_percentage”: 100,  
“borrower”: {  
“id”: 118687,  
“name”: “PT. Arabika Nusantara”,  
“description”: “”,  
“image\_url”: null,  
“total\_financing”: 43,  
“member”: 50,  
“location”: “Agroyasa Farm”,  
“latitude”: “-6.7992111”,  
“longitude”: “106.7002202”  
}  
});
