# Quick Assistance With Nested Objects

**URL:** <https://community.postman.com/t/quick-assistance-with-nested-objects/12275>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [April 28, 2020, 7:17pm UTC](https://community.postman.com/t/quick-assistance-with-nested-objects/12275 "2020-04-28T19:17:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![austin4778](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@austin4778](https://community.postman.com/u/austin4778)\
**Post date:** [April 28, 2020, 7:17pm UTC](https://community.postman.com/t/quick-assistance-with-nested-objects/12275/1 "2020-04-28T19:17:16Z")

</div>

Performing a GET request that returns in XML format. I converted that to JSON as outlined below. I am looking to parse an array and set an array as an env variable for each specific object in the array.

Path to data I want to retrieve:

`BESAPI.Query.Result.Tuple.Answer[0]._`

Here is my action script:

```
var jsonData = xml2Json(responseBody);

var ActionIDs = [];

_.each(jsonData.BESAPI.Query.Result.Tuple[0].Answer[0]._, () => {
ActionIDs.push(jsonData.BESAPI.Query.Result.Tuple[1].Answer[0]._)
})

pm.environment.set("ActionID", ActionIDs.shift());
    

pm.environment.set("ActionIDs", JSON.stringify(ActionIDs));

pm.test("Status code is 200", function () {
    console.log(pm.response.code);
    pm.response.to.have.status(200);

});

```

Attached a screenshot of my JSON response body. How can I achieve looping through Tuple.Answer to get all highlighted values for each object from the response? With the current test scripts I am getting the following in my ActionIDs env variable:

`["1965555","1965555","1965555","1965555","1965555","1965555"]!`

 ![Capture](https://us1.discourse-cdn.com/getpostman/original/3X/c/0/c0169806e509aafa9e80c8486715a96ba89d3e86.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 29, 2020, 9:36am UTC](https://community.postman.com/t/quick-assistance-with-nested-objects/12275/2 "2020-04-29T09:36:07Z")

</div>

Hey @austin4778

Something like this should create an array of those values and store them as an environment variable:

```
let jsonObject = xml2Json(responseBody),
    ActionIDs = [];
    
_.each(jsonObject.BESAPI.Query.Result, (arrItem) => {
    _.each(arrItem, (result) => {
        ActionIDs.push(result.Answer[0]["_"])
    })
})

pm.environment.set("ActionIDs", JSON.stringify(ActionIDs));
```

---

<div class="post-metadata">

**Author:** ![austin4778](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@austin4778](https://community.postman.com/u/austin4778)\
**Post date:** [April 29, 2020, 1:54pm UTC](https://community.postman.com/t/quick-assistance-with-nested-objects/12275/3 "2020-04-29T13:54:29Z")

</div>

Thank you very much! My syntax was a little off 😊
