'Postman - dynamic variable for a value from array

How could I add an automatic environmental variable in Postman based on a value which is appearing in the endpoint response in the array?

In the example below, I would like to use the "id3" value and save it as a dynamic variable.

    {
    "test": 123,
    "test2": [],
    "test3": [
            {
                "id": 0,
                "id2": 4554336,
                "id3": 30,
                "id4": 0
            }
        ]
    }

I thought it will be simple as:

let jsonData = pm.response.json();
pm.environment.set("test_name", jsonData.test3.id);

but this set up is saving the variable with a null value.



Solution 1:[1]

 let jsonData = pm.response.json(); 
pm.environment.set("test_name", jsonData.test3[0].id3);

test3 is an array so you have to get the first object and then id3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PDHide