Hi, I am trying to run below code to find the row count for the JSON response but i am getting the assertion error. Could you please help me out with solution:
var jsonData = pm.response.json();
var rowCount = jsonData.length;
console.log(jsonData)
pm.test(“Check row count”, function () {
pm.expect(rowCount).to.be.above(0);
});
JSON response is in form of Array.
error: Check row count | AssertionError: expected undefined to be a number or a date
The error is telling you that the first element is undefined (rowCount).
Length only works against arrays.
your jsonData at the top level is not an array. Therefore you can’t use length.
The data element is an array, so it sounds like it should be.
var rowCount = jsonData.data.length
For troubleshooting purposes, when you get errors like this. Console log the variable that you are having issues with. If its undefined, then its not finding the element you are trying to target.
Can you also please use the preformatted text option within the editor when showing code or example responses. It stops all of the text being aligned to the left, which is harder to read.