How can i save a response value for an id from an array response?

Hi there,
I’m struggling to store the response of this id into the variables please, i will appreciate all answers
:

{
    "test": {
        "id": "2e2e2-2e2e2e-2e2e2e-2e2e2e-2e2e",
        "testname": "Test123"
    }
}:

While i’m trying to store variables its storing Null in the variables:

I’ve already tried pm.environment.set("testid", pm.response.json().id); and

let response = pm.response.json(),
   id = JSON.parse(response);
pm.environment.set("testid", response);

Hey @aerospace-cosmonaut2 :wave:

Given the structure of that response, it would be this:

let response = pm.response.json();
pm.environment.set("testid", response.test.id);

You need to reference each part of the JSON, as you work down through it to get the value. You went straight to id and didn’t include test in the reference.

1 Like

Omg thank you soo much, i was struggling.

1 Like