# How to get a value from variable when response in under id

**URL:** <https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [February 24, 2021, 6:27pm UTC](https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755 "2021-02-24T18:27:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skondur](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@skondur](https://community.postman.com/u/skondur)\
**Post date:** [February 24, 2021, 6:27pm UTC](https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755/1 "2021-02-24T18:27:45Z")

</div>

I want add Id number to Environment variable  
I used

const TestCaseInfo = pm.response.json()  
pm.environment.set(“TestCaseID” , TestCaseInfo.id);

not able to get " id" due to Id is under the “12871” ,and 12871 changing every run .

here is the response  
{

```
"12871": {

    "id": 12871,

    "orderId": 11415,

    "executionStatus": "-1",

    "executionWorkflowStatus": "CREATED",

    "comment": "",

    "htmlComment": ""

```

}

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [February 24, 2021, 7:05pm UTC](https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755/2 "2021-02-24T19:05:53Z")

</div>

Hi @skondur, Welcome to the community.

The JSON provided by you seems to be invalid. Taking below valid JSON as an example.

```auto
{
"12871": {
    "id": 12871,
    "orderId": 11415,
    "executionStatus": "-1",
    "executionWorkflowStatus": "CREATED",
    "comment": "",
    "htmlComment": ""
}
}

```

It seems the value of id is coming in key of JSON object. One way to extract the object is to extract keys from the JSON object.

```auto
const mark1= pm.response.json();
const key = Object.keys(mark1)[0];//assuming, the first key is your ID
console.log(key);

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![skondur](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@skondur](https://community.postman.com/u/skondur)\
**Post date:** [February 24, 2021, 9:01pm UTC](https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755/3 "2021-02-24T21:01:16Z")

</div>

Hi Pranav ,  
yes I missed } at the end , but Solution you provided worked . thanks for the Quick response.

Thanks  
Kondur.

---

<div class="post-metadata">

**Author:** ![varundhivya](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@varundhivya](https://community.postman.com/u/varundhivya)\
**Post date:** [October 16, 2021, 10:13am UTC](https://community.postman.com/t/how-to-get-a-value-from-variable-when-response-in-under-id/20755/4 "2021-10-16T10:13:29Z")

</div>

In syntax, which is used to refer to that variable. Spaces are not allowed in variable names. It’s worth noting that changing a variable’s name has no effect on the data; all values linked with the variable remain unchanged. Renaming a variable merely changes its name while leaving the rest of its contents unchanged [The Best Crossfit Gloves – Buying Guide and Reviews(2021 update) - Rigor Fitness: Fat Loss, Muscle Gain, Strength Gain](https://rigorfitness.com/best-crossfit-glove/).
