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