I am using postman to do API testing. My response message is
[
{
"firstName": "Jia",
"lastName": "Tes",
"memberId": 745794,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
},
{
"firstName": "Jia",
"lastName": "Test2",
"memberId": 745746,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
},
{
"firstName": "Jia",
"lastName": "Test3",
"memberId": 745748,
"branchId": 12443,
"branchName": "Clubware Mobile Test Branch 2 (Pub)"
},
{
"firstName": "Jia",
"lastName": "Test3",
"memberId": 745745,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
}
]
I would like to get "memberId" where "firstName": "Jia","lastName": "Test3" and "branchName": "NZ - Clubware Mobile Test Branch 1"
my current code is like
var response = JSON.parse(responseBody);
console.log("BODY:" + response[3].memberId);
but i don't like use index to locate element in list, how can I do that, thank you guys!!
If you just wanted to check for a specific value, you could use the _.find() Lodash function to get the memberId
value:
var user = _.find(pm.response.json(), {
firstName: "Jia",
lastName: "Test3",
branchName: "NZ - Clubware Mobile Test Branch 1"
})
console.log(user.memberId)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With