# How to use json.parse(responseBody) to store multiple nested variables?

**URL:** <https://community.postman.com/t/how-to-use-json-parse-responsebody-to-store-multiple-nested-variables/42411>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [December 27, 2022, 5:28pm UTC](https://community.postman.com/t/how-to-use-json-parse-responsebody-to-store-multiple-nested-variables/42411 "2022-12-27T17:28:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwestein](https://avatars.discourse-cdn.com/v4/letter/b/b9bd4f/32.png) [@bwestein](https://community.postman.com/u/bwestein)\
**Post date:** [December 27, 2022, 5:28pm UTC](https://community.postman.com/t/how-to-use-json-parse-responsebody-to-store-multiple-nested-variables/42411/1 "2022-12-27T17:28:38Z")

</div>

I saw several similar posts to solve this issue, but none that are exactly what I was looking for.

I can successfully use this code to store a local variable **test1Id**. Where variable is **test1Id** value 174 is stored locally:

var jsonData = JSON.parse(responseBody);  
pm.environment.set(“test1Id”, jsonData[“test1Id”]);

I have not been able to store another variable that is nested in the same response – testPeriodId where value is 239:

{  
" **test1Id": 174** ,  
“organizationId”: 1,  
“organizationName”: “Art”,  
“test”: “API Test23”,  
“testPeriods”: [  
{  
" **testPeriodId": 239** ,  
“test1Id”: 174,  
“startDate”: “2022-12-23T00:00:00”,  
“startDateString”: null,  
}  
]

I have tried different codes, but I always get NULL stored for **testPeriodId**

**Sample Tests:**  
var jsonData = JSON.parse(responseBody);  
pm.environment.set(“test1Id”, jsonData[“test1Id”]);

var jsonData = JSON.parse(responseBody);  
pm.environment.set(“testPeriodId”, jsonData[“testPeriods[0].testPeriodId”]);

---

<div class="post-metadata">

**Author:** ![jetison](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jetison/32/12_2.png) [@jetison](https://community.postman.com/u/jetison)\
**Post date:** [December 27, 2022, 6:09pm UTC](https://community.postman.com/t/how-to-use-json-parse-responsebody-to-store-multiple-nested-variables/42411/2 "2022-12-27T18:09:12Z")

</div>

It looks like you’re misplacing the double quote or closing square bracket. If you’re trying to reference `testPeriodId`, you can do it like `jsonData["testPeriods"][0]["testPeriodId"]`. Or use a dot notation like `jsonData.testPeriods[0].testPeriodId`

If you’re getting stuck on parsing the object, I recommend using `console.log(jsonData)` and then drilling down into the nested object by following it with `console.log(jsonData["testPeriods"])`, and then `console.log(jsonData["testPeriods"][0])`, and so on. [Debugging with the Console | Postman Level Up - YouTube](https://youtu.be/YCsURct9wCk)
