Test if json list has max lenght of 5 POSTMAN, JS

Viewed 22

I gotta assert that a json list can have a maximum of 5 elements. My problem is how do I do this in postman framework.

The list can have either 1 or 5 elements, this is dynamic, i gotta verify it never has more than 5.

var data = JSON.parse(responseBody);
data.servers.lenght would return the number of elements in the list

Any ideas?

1 Answers

So the answer is quite simple using .below already provided by postman

pm.test("Less than 6 servers.", function () { 
    pm.expect(data.servers.length).to.be.below(6);
});
Related