Postman- Retrieve specific key values from JSON object

How to get the specific key values in the form of an Array or List.

e.g.

{
    "description": "demo",
    "status": "test",
    "name": "mytest",
    "members": [
        {
            "UserId": "886af1af66",
            "Name": "u1",
            "email": "[email protected]"
        },
        {
            "UserId": "0aa280686",
            "Name": "u2",
            "email": "[email protected]"
        },
        {
            "UserId": "0dc888888",
            "Name": "u3",
            "email": "[email protected]"
        }
    ]
}

Expected outcome: [‘[email protected]’,‘[email protected]’,‘[email protected]’]

Postman uses JavaScript under the hood, so this is more of a JavaScript query.

This can be achieved using the JavaScript map function.

JavaScript Array map() Method (w3schools.com)

const response = pm.response.json();
let emails = response.members.map(members => members.email);
console.log(emails);

image

1 Like