postman read property in json response which name is saved in array

I am trying to check values of certain properties in json response in postman.


The thing is, that I need to check multiple properties which names I have stored in an array.

var jsonData = pm.response.json();
var keys = ["id", "phoneNumber", "passwordHash"];

pm.test("All values have valid value", function(){
   for(var a = 0; a < keys.length; a++){

But I am getting this error:

All values have valid type | TypeError: Cannot read property ‘0’ of undefined

Can someone explain me, what am I doing wrong please?
Thanks for any advice.

>Solution :

You cann’t use (.) dot to get a value of a unknown key, use [] bracket instead. Try this:


One subtle thing, in my opinion, use i (mean index) is better than a.

Leave a Reply