Quick Assistance With Nested Objects

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"]!

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

Thank you very much! My syntax was a little off :blush: