How to verify multiple values in array

This is my response I need verify values

{
    "status": "success",
    "data": {
        "actions": [
            {
                "result": "https://"example/312922896055201.jpg",
                "original_image": "example/312922896055201.jpg",
                "type": "image",
                "destination_size": {
                    "h": 2504,
                    "w": 2000
                },
                "resource": {
                    "license": "fte",
                    "resource_url": "example/312922896055201.jpg",
                    "resource_id": "312922896055201",
                    "source_type": "company",
                    "type": "photo"
                }
            },

For result in actions array I wrote this code

let jsonDataResult = pm.response.json();
pm.test("Result is correct", function () {
    var jsonDataResult = pm.response.json();
    pm.expect(jsonDataResult.data.actions[0].result).to.eql("example/312922896055201.jpg");
});

But for type in actions array the same is not working

let jsonDataType = pm.response.json();
pm.test("Type is correct", function () {
    var jsonDataType = pm.response.json();
    pm.expect(jsonDataType.data.actions[1].type).to.eql("image");
});

What to do?
Thanks in advance.

Your array does not seem to have two elements.

So try

jsonDataType.data.actions[0].type

2 Likes

In case if the action is more than 100+ then ?

@poornapragnaps Welcome to the community :bouquet:

In that case it is advised to loop over the array. Basic would be using traditional for loop if your a newbie. You have many of those queries answered across the the forum :blush:

Hi @bpricilla, Actually I tried it and even search similar JSON array one, but I couldn’t.
Could you pls help me with this issue? Thanks in advance.

Thanks,
Poorna.