Skip to content Skip to sidebar Skip to footer

Postman Test Scripts: Inspecting Contents Of Response Json

PostMan 6.0.10 here. I'm trying to understand how to write test scripts a little better, and after reading their otherwise superb documentation I still have some confusion surround

Solution 1:

This is basic but should work to get the dynamics:

pm.test("Verify payload of example one",  () => {
    pm.expect(pm.response.json()[0].fizz).to.equal('buzz')
    pm.expect(pm.response.json()[0].foo).to.equal(53)
    pm.expect(pm.response.json()[1].fizz).to.equal('bozz')
    pm.expect(pm.response.json()[1].foo).to.equal(291)
});

pm.test("Verify payload of example two",  () => {
    pm.expect(pm.response.json().fizz).to.equal('buzz')
    pm.expect(pm.response.json().foo).to.equal(293)
});

Might be worth researching some basic JavaScript and how to parse JSON objects.

Solution 2:

//You can do something like this

if (responseCode.code === 200) {
  var jsonDataArray;
  var jsonArray= JSON.parse(responseBody);
 var found=false;

       for (var i = 0;i<jsonArray.length;i++){`enter code here`

     jsonDataArray = jsonArray[i];
     for (var j = 0; j<jsonDataArray.length && found === false;j++){
         if (jsonDataArray[j].fizz === "buzz" && jsonDataArray[j].foo === 53)

Post a Comment for "Postman Test Scripts: Inspecting Contents Of Response Json"