# Extract value from response

**URL:** <https://community.postman.com/t/extract-value-from-response/17143>\
**Category:** Help Hub\
**Tags:** tests, variables, response\
**Created:** [October 27, 2020, 12:26pm UTC](https://community.postman.com/t/extract-value-from-response/17143 "2020-10-27T12:26:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ereddy068](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ereddy068](https://community.postman.com/u/ereddy068)\
**Post date:** [October 27, 2020, 12:26pm UTC](https://community.postman.com/t/extract-value-from-response/17143/1 "2020-10-27T12:26:49Z")

</div>

I am trying to extract the value from json response to a variable and use it different api call.  
I am always getting response as {equipmentId: 35001565}  
I need only 35001565 in my variable.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/4/b49a671a53b44ec220cdd7994e5a4ff8ec014751.png)

I am new to postman and started using a week back, tried looking for solution and most of the results are about arrays, so posting a new thread here

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [October 27, 2020, 12:40pm UTC](https://community.postman.com/t/extract-value-from-response/17143/2 "2020-10-27T12:40:44Z")

</div>

Welcome to the community @ereddy068!

Are you familiar with JSON at all? That’s going to make your Postman life significantly easier.

If you add this script into the Tests tab, it will add the `equipmentId` as a collection variable:

```auto
const jsonData = pm.response.json();
pm.collectionVariables.set('equipmentId', jsonData.equipmentId);

```

Then in any request you need to use that on, you can just use `{{equipmentId}}` to reference it.

---

<div class="post-metadata">

**Author:** ![ereddy068](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ereddy068](https://community.postman.com/u/ereddy068)\
**Post date:** [October 27, 2020, 12:42pm UTC](https://community.postman.com/t/extract-value-from-response/17143/3 "2020-10-27T12:42:47Z")

</div>

Thank you allen.

I was in a belief that postman will give autosuggestion of values if we give . at the end of jsondata.  
Now I understood the process.

---

<div class="post-metadata">

**Author:** ![ashuhhh38](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ashuhhh38/32/9857_2.png) [@ashuhhh38](https://community.postman.com/u/ashuhhh38)\
**Post date:** [September 28, 2021, 7:08am UTC](https://community.postman.com/t/extract-value-from-response/17143/4 "2021-09-28T07:08:27Z")

</div>

Hi @allenheltondev , if there are nested values, for eg,  
sort": [  
{  
“direction”: “ASC”,  
“property”: “name”,  
“ignoreCase”: false,  
“nullHandling”: “NATIVE”,  
“ascending”: true  
}

How can I extract the value of ‘direction’ and use it for further assertions?  
Tried using : pm.expect(jsonData.direction).to.eql(“ASC”);  
got error : AssertionError: expected undefined to deeply equal ‘ASC’

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [September 28, 2021, 11:40am UTC](https://community.postman.com/t/extract-value-from-response/17143/5 "2021-09-28T11:40:24Z")

</div>

Hey @ashuhhh38,

Your response is an array, so you’ll have to handle it by index. Do you know if you will always only have one result? If so, you could update your assertion to:

```javascript
pm.expect(jsonData.sort[0].direction).to.equal('ASC'))

```

If there will sometimes be multiple values, you’ll have to figure out what you want to do there.
