How to count length of response in new syntax

I am struggling with the new syntax and would need your input. How can you write below test with pm? (the new syntax)

responseJson = JSON.parse(responseBody);
tests["Nr of plans returned = " +responseJson.length] = responseJson.length === 2;

I appreciate your help!

Hey @captain_hoy, here’s how you can achieve what you want with the new pm.* syntax.

var data = pm.response.json();

pm.test('Number of plans returned = ' + data.length, function () {

In case you want to check the count of keys in a JSON object, simply replace data with Object.keys(data) and you’ll be good to go.

Also, you can access the complete API reference here in case you would like to check it out. Hope this helps.


@deepak.pathania thank you

hi, how can i get the count and name of the response body in API POSTMAN ,PLEASE GIVE ME A SUGGESTION.

new to this syntax, what about if the json had no root, how do you use the Json as Json Array length: pm.test(Count: ${pm.response.json().length}) seems to only look at the entire json?

Json response without root:

        "id": "1"
        "id": "2"