Unable to save value of responde to environment value

Hi there,

I’m struggling to store the response of an “id” into the variables. My lack of good JS-knowledge is killing me.

I will appreciate all answers. I am trying to set the “id” value to an environment variable called “id”. Value at this moment is “null”


    "value": [
            "id": 4284,
            "groupType": "XXXX",
            "groupName": "XXXXXXXXXXXX_read",
            "description": "",
            "location": "\\"
    "count": 1

Testscript I am using:

var jsonData = JSON.parse(responseBody)
let response = pm.response.json();
pm.environment.set("id", jsonData["value[0].id"]);

Searched through similar topics on the forum but can’t seem to get this working

Hey @payload-pilot-982550

This is quite a common issue when working with JSON arrays [...] and objects {...} - Just need to ensure that the references you have are pointing to the right place.

You were close with your script but I amended it to make the reference to the id work correctly.

let response = pm.response.json();
pm.environment.set("id", response.value[0].id);

@payload-pilot-982550 Welcome to the Community :partying_face:

As @dannydainton mentioned, everyone faced this at one point during the early days of Postman :grinning:

This tool helped me lot: https://jsonpathfinder.com/

I wrote a blog here about how to use it.


Worked like a charm. Thank you!!

1 Like