# Postman - How to get value from json array

**URL:** <https://community.postman.com/t/postman-how-to-get-value-from-json-array/29473>\
**Category:** Help Hub\
**Tags:** json\
**Created:** [November 7, 2021, 5:21pm UTC](https://community.postman.com/t/postman-how-to-get-value-from-json-array/29473 "2021-11-07T17:21:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mission-saganist-751](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mission-saganist-751](https://community.postman.com/u/mission-saganist-751)\
**Post date:** [November 7, 2021, 5:21pm UTC](https://community.postman.com/t/postman-how-to-get-value-from-json-array/29473/1 "2021-11-07T17:21:51Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

Hi everyone,  
I am new to JSON and Postman. I’m trying to do something very simple.

I have a GET request which will get a JSON response like the one below.

In the example below from inside of the `data` array, I want to get the value of `benefitGeneralID` but only if the value matches a specific `uniqueCode` ,eg- `name123code`

How can I do it? Thanks in advance

_Details (like screenshots and the response body)_:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/b/ab801d5b132704d8c02e9e306900418f34222a0d.jpeg)

- {  
“data”: [  
{  
“setUp”: 5,  
“warrantsLimitation”: true,  
“noOfWarrants”: null,  
“warrantsGrossValue”: null,  
“adminFee”: 3.00,  
“maximumThresholdAmount”: 1000.00,  
“maximumPercentage”: 100.00,  
“impactBudget”: null,  
“impactNetSalary”: null,  
“impactBIK”: null,  
“impactSocSec”: null,  
“benefitGeneralId”: “d928ds4b2d-fsd357-**-955d-1ef07303c70b",  
“benefitId”: "1a372419-**-4a16-abd9-75a9da74b9e7”,  
“benefitType”: 22,  
“name”: “Warrant 3”,  
“nameInDutch”: “Warrant 3”,  
“nameInFrench”: “Warrant 3”,  
“startDate”: “2018-10-01T00:00:00.000”,  
“endDate”: “2022-02-03T00:00:00.000”,  
“uniqueCode”: “abcde”  
},

{  
“setUp”: 3,  
“warrantsLimitation”: null,  
“noOfWarrants”: 10,  
“warrantsGrossValue”: 100.00,  
“adminFee”: 3.00,  
“maximumThresholdAmount”: 1000.00,  
“maximumPercentage”: 100.00,  
“impactBudget”: null,  
“impactNetSalary”: null,  
“impactBIK”: 100.00,  
“impactSocSec”: 0.00,  
“benefitGeneralId”: “23bb27c6-9a1e-46f5-8501-567da25fb5e5”,  
“benefitId”: “1a372419-43a6-4a16-abd9-75a9da74b9e7”,  
“benefitType”: 22,  
“name”: “name123”,  
“nameInDutch”: “name123”,  
“nameInFrench”: “name123”,  
“startDate”: “2018-10-01T00:00:00.000”,  
“endDate”: “2022-02-05T00:00:00.000”,  
“uniqueCode”: “name123code”  
},  
{  
“setUp”: 4,  
“warrantsLimitation”: true,  
“noOfWarrants”: null,  
“warrantsGrossValue”: 1000.00,  
“adminFee”: 3.00,  
“maximumThresholdAmount”: 10000000.00,  
“maximumPercentage”: null,  
“impactBudget”: null,  
“impactNetSalary”: null,  
“impactBIK”: null,  
“impactSocSec”: null,  
“benefitGeneralId”: “3e3bb656-dbb2-**-a98c-c36d44b70207",  
“benefitId”: "1a372419-**-4a16-\*\*\*\*-75a9da74b9e7”,  
“benefitType”: 22,  
“name”: “Free choice (amount)”,  
“nameInDutch”: “name1234code”,  
“nameInFrench”: “name1234code”,  
“startDate”: “2021-08-30T06:30:00.000”,  
“endDate”: “2021-09-30T06:30:00.000”,  
“uniqueCode”: name1234code"  
},

],  
“total”: 2,  
“aggregateResults”: null,  
“errors”: null  
}

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [November 8, 2021, 8:59am UTC](https://community.postman.com/t/postman-how-to-get-value-from-json-array/29473/2 "2021-11-08T08:59:31Z")

</div>

Hey @mission-saganist-751!

So, to get the benefitGeneralID from the response, we simply loop through the data, test for the required condition and save the required value,

One way to do this is:

```auto
//Saving the response from the GET request
var response=pm.response.json();
//Fetching the data array and storing it
var data=response.data, Ids=[]; //Ids to store benefitGeneralID

//looping through each data item
_.each(data, (item)=>{

    //Required condition
    if(item.uniqueCode==="name123code")
       Ids.push(item.benefitGeneralId);
})

console.log(Ids);

```

Good luck!

---

<div class="post-metadata">

**Author:** ![mission-saganist-751](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mission-saganist-751](https://community.postman.com/u/mission-saganist-751)\
**Post date:** [November 8, 2021, 1:36pm UTC](https://community.postman.com/t/postman-how-to-get-value-from-json-array/29473/3 "2021-11-08T13:36:29Z")

</div>

Thanks for the code 🙂

really appreciate it.
