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.

Could you please help me on this issue
need to verify the values in the array T2, however the array T2 is dynamic in nature and the location of the array will change dynamically from (0,1), however the below test codes are not working in this case. Please see the below code. thanks

“body”: {

    "Inventory1": [
        {
            "id1": 1234,
            "id2": "test1",
     
            "W1": [
                {
                    "SKU1": "23423",
                    "product1": "Test1",
                    "Transaction1": {
                        "Product1": "",
                        "Product1": "23432",
                    },
                    "T2": [
                        {
                            "SKU1": "67575",
							"product1": "Test2",
                        }
                    ]
                },
                {
                    "SKU": "6456",
                    "product": "Test2",
                    "Transaction2": {
                        "Product2": "",
                        "Product2": "23432"
                    }
                }
            ],
            "T3": [
                {
                    "SKU": "5435",
					"product": "Test3",
                }
            ]
        }
    ],
}

let T2 = jsonData.body.Inventory1[0].W1.forEach(a => a.SKU1 === '67575');
pm.expect(T2.SKU1).to.be.eql('67575');
pm.expect(T2.product1).to.be.eql('Test2');