Extract a string from array response

Hello all,

I’m trying to extract a single property filed from each object of array and pass on to another GET request.

Below is the response and from the response, I need to extract all the "name" field and iterate them to another request like below

GET https://BASE_URL/api/v1/{{name}}

[
     {
           "name":  "User1",
            "realm":  "ldap"
     },
     {
           "name":  "User2",
            "realm":  "ldap"
     },
     {
           "name":  "User3",
            "realm":  "ldap"
     }
]

I have tried the below one:

var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("User", data[0].name);

This is storing all the user name like ["User1", "User2", "User3"] But I’m not sure how to iterate them. Please help me on this. Thanks in advance.

Hey @rav.adonis :wave: Welcome to the Postman Community :rocket:

You can loop over a request using array.shift() and postman.setNextRequest() by dynamically updating an array. I have created a sample collection in my Public Workspace to demonstrate this.

I hope this helps! :smiley: Let me know if you have further questions!