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

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”]);

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