Parse a nested array

I am trying to parse the response body (JSON) which has multiple arrays nested within a larger array. I cannot figure out how to access the specific details within the furthest nested array. I want to confirm that all values of “Quantity” are greater than 20.

I have attached an image of the body (the 1st image) and the response body (the 2nd image).

For example: if one instance “Quantity” is 19, I want the test to fail

Hey, to be clear, you want accessForecastDetails and the Quantity of each SKU?

If you shared your Test script so we can see that would help, also try attaching the JSON request object or even just copy and paste it here so I can play with.

But trying to look I’d guess you could try to access it using:

let resp = pm.response.json();
//this would be for that single array
resp.ForecastDetails[0].ForecastWeeks[0].ForecastLines.filter(x => x.Quantity == 19); 

You’d need to do a lot of looping for all the arrays. I just did what I could see based off the JSON object.

If you want to test against that I suppose you can loop in the expect in the test function.

pm.test("Not Equal 19", () => {
    resp.ForecastDetails[0].ForecastWeeks[0].ForecastLines.forEach(x => pm.expect(x).to.not.equal(19)); 

I’m going to try this out myself. I’m not sure if the forEach loop with pm.expect will work. I’ll report back when I test.

Either way, if I could see the whole object, I could probably write better selection code.