Access nested array response values

I have a sample Json response in here when I dot a hippo GET.
Please help me to get the list of values. Please help me to get the sourcelineItemId s.

I tried with below, but it is not working

const FssRes = http.get(getFSSUrl, params);
   console.log('Source lineitems - ' + FssRes.json().data.lineItems.source.lineItemId);

response payload

{
    "data": {
        "Id": "9cedfc4c-fa58-4ea8-9dc0-a53e3610b873",
        "workspaceId": "1219d091-c096-4a97-9955-a2b2e7efbb14",
        "workspaceStatus": "CREATED",
        "lineItems": {
            "source": [
                {
                    **"sourcelineItemId": "f287597d-cbf4-4e07-aca7-7bea9f0a2ad3",**
                    "amount": 400.00,
                    "authorised": null,
                    
                 
                },
                {
                    **"sourcelineItemId": "d10e4b5c-0939-4979-9465-239d66f48448",**
                    "amount": 400.00,
                    "authorised": null,
                  
                    }
                }
            ],
            "destination": [
                {
                    "destlineItemId": "e4647a48-332f-4d4c-af9f-f56b42aebfc6",
                    "amount": 400.00,
                    "authorised": null,
                
                    }
                },
                {
                    "destlineItemId": "3e6bea44-9c59-4e82-9d5a-6fb15dca0c22",
                    "amount": 400.00,
                    "authorised": null,
                    }
                }
            ]
        }
    },
    "errors": []
}

Hi @ushanib,
the syntax for the json selector is documented here (as mentioned from the k6 documentation). I haven’t tried with your returned data but it seems you are missing the # character for accessing the child path of the source array.

   console.log('Source lineitems - ' + FssRes.json().data.lineItems.source.#.lineItemId);

Let me know if it helps.

1 Like