Assertion error for Row count

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;


pm.test(“Check row count”, function () {



JSON response is in form of Array.

error: Check row count | AssertionError: expected undefined to be a number or a date

JSON response Example:

“error”: false,
“errorCode”: null,
“errorMessage”: null,
“data”: [
“venue”: “Lab testing”,
“number”: “38837839377”,
“provider”: “Airtel”,
“deliveryTimestamp”: 1674737560785,
“smsTimestamp”: 1674737556903,
“type”: “OTP”,
“message”: "this is your OTP,
“deviceId”: “56:53:12:34:9e:7e”,
“deviceName”: “Test”,
“mac”: “3e:a1412:f7:59:ea”,
“deliveryStatus”: “DELIVERED”,
“status”: “Success”

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 =

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.

On a side note, if you want to count the number of objects within an object (just in case they are not returned as an array).

You can do this using the built in lodash library within Postman


Or without lodash, you can use…


Object.keys returns an array of the keys which means you can then use the length function.