Set Postman variable based on a json without tag

I’m pretty new with using postman and I’m trying to store one part of the JSON response of my request in a variable. My problem is that the JSON doesn’t have tags. It looks like this:


Is it possible to store the JSON as an array and create variables like this: id1=response[0], id2=response[1]?
Thanks in advance!

>Solution :

Assuming the response is just like you described, you can do this using the "Tests" tab in your Postman request.

Postman tests tab

Here is the code

// If the response is exactly like you described (You may have to adapt the query to get your array)
const resp = pm.response.json()

for (var i = 0;i<resp.length;i++) {
    pm.environment.set("id"+i, resp[i]);

This result like this in your Env catalog:

Env results

Leave a Reply