Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

[
    "01000511",
    "00000001",
    "00000009",
    "01000654"
]

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading