Need help - How to set a variable for responses starting with [ instead of {

hi all, I have a response structure like below
[
{
“abc”: “123”,
“number”: “ABC”
},
{
“abc”: “1234”,
“number”: “ABCD”
}
]
I want to extract the first value and all the values of the field “number” from the response. Need some help on how to do it.

Hi @pushpender07, welcome to the Postman community :slight_smile:

You’ll need to assign this to a variable to be able to manipulate it using JavaScript.
Here’s how you would print every number value in the console:

var content = [ 
   { 
      "abc":"123",
      "number":"ABC"
   },
   { 
      "abc":"1234",
      "number":"ABCD"
   }
]

for(i = 0; i < whatev.length; i++) { 
   console.log(whatev[i].number) 
}

To learn more about manipulating JSON arrays, you can refer to the MSDN documentation right here:

Thank you, it worked.

1 Like