# Need help in extracting the value

**URL:** <https://community.postman.com/t/need-help-in-extracting-the-value/8055>\
**Category:** Help Hub\
**Tags:** tests, variables, collections\
**Created:** [September 27, 2019, 5:57pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055 "2019-09-27T17:57:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![saveuser12345](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@saveuser12345](https://community.postman.com/u/saveuser12345)\
**Post date:** [September 27, 2019, 5:57pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/1 "2019-09-27T17:57:09Z")

</div>

Hi All,

I have store the below result in a environment variable called **Key\_value** and want to retrieve the Id value from this variable and used it in the next post request. Can some one help me how to achieve the same.

{  
“objects”: [  
{  
“id”: “9yQeoXHnw0ykkfKz5zzZCL”,  
“path”: “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”,  
“type”: “MTT”,  
“description”: “”,  
“updatedBy”: “System”,  
“updateTime”: “2018-07-10T09:07:33Z”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 27, 2019, 6:22pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/2 "2019-09-27T18:22:14Z")

</div>

Hey @saveuser12345,

I wrote this post that might help you out:

> [@Sharing tips and tricks with others in the Postman community](https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community/5123/5):
>
> Extracting values from a JSON response I notice lots of questions from the community which all have a similar flavour - Users are having trouble extracting data from a JSON response body when the value is within an array. These are normally JavaScript related questions, more than specific Postman questions but I want to use this thread to offer more support around this problem. For these examples I’ll be using the [https://randomuser.me](https://randomuser.me) API, this returns lots of random user data, in a JSON form…

---

<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:** [September 27, 2019, 6:22pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/3 "2019-09-27T18:22:56Z")

</div>

Hi @saveuser12345,

Go ahead and execute the below test script

```auto
key = JSON.parse(pm.environment.get("Key_value"));
id = key.objects[0].id;

```

---

<div class="post-metadata">

**Author:** ![saveuser12345](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@saveuser12345](https://community.postman.com/u/saveuser12345)\
**Post date:** [September 27, 2019, 6:28pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/4 "2019-09-27T18:28:51Z")

</div>

HI ahmed,

I have used the above script in the pre request part of post request and i am using body as mentioned below and it is throwing error here Id is the value retreived from above scripts . i have to use the value “9yQeoXHnw0ykkfKz5zzZCL” in my body of next request which is what i am expecting in the {{id}} value.

{  
“@type”: “job”,  
“taskFederatedId”:"{{id}}",  
“taskType”: “MTT”  
}

---

<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:** [September 27, 2019, 6:34pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/5 "2019-09-27T18:34:52Z")

</div>

Hi @saveuser12345,

For you to use the extracted value of id in the body of the request, you would need to set the value of id to an environment or global variable as given below and then access it using the double brackets in the request:

```auto
key = JSON.parse(pm.environment.get("Key_value"));
pm.environment.set("id", key.objects[0].id);
or
pm.globals.set("id", key.objects[0].id);   

```

---

<div class="post-metadata">

**Author:** ![saveuser12345](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@saveuser12345](https://community.postman.com/u/saveuser12345)\
**Post date:** [September 27, 2019, 6:36pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/6 "2019-09-27T18:36:50Z")

</div>

Hi Ahmed,

Thanks that worked fine for me. but may i understand objects[0] means what in your statement.

---

<div class="post-metadata">

**Author:** ![saveuser12345](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@saveuser12345](https://community.postman.com/u/saveuser12345)\
**Post date:** [September 27, 2019, 6:43pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/7 "2019-09-27T18:43:11Z")

</div>

Hi Ahmed,

Can you help in the below past as well.

# [Download file when send request](https://community.postman.com/t/download-file-when-send-request/2471).

---

<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:** [September 27, 2019, 7:24pm UTC](https://community.postman.com/t/need-help-in-extracting-the-value/8055/8 "2019-09-27T19:24:25Z")

</div>

Hi @saveuser12345,

I think it would be better if you follow up in the mentioned thread if you are still facing issues using the collection .
