Postman newman is converting json array of objects to String

Trying to get the the length of json array of objects, in postman UI it is showing correctly but when running the same script in postman newman it is showing wrong value.

Input Data:

Postman UI output:-


Postman newman output:-


It looks like it should be “string”.

How are you generating the output?

Top result (Postman UI output) is by running request in Postman it self and other result (Postman newman output) is running request in CLI using newman’s command.

I am trying to get the length of the plans list objects. [Pls refer screenshoot above]

I mean how are you generating the strings in the console log.

The UI looks like its from the Console Log.

I want to see how you are getting the count and type and generating the two “strings”.

The Newman output doesn’t look like Console logs. But let start with the UI first.


var jsonData = JSON.parse(responseBody);

console.log("Data Count: "+jsonData.plans.length)

console.log("Data Type: "+typeof (jsonData.plans))

The UI is correct then.

When you parse the response, it creates a JavaScript object.

JavaScript objects can contain other objects.

The Plans element is an object. It’s also an array, which is a special type of object which allows you to test like the following.

const jsonData = pm.response.json(); // JSON.parse(responseBody) is the old way of doing this.

pm.test("Expect plans array to exist", () => {

Now we’ve got that out of the way.

Where is the Postman Newman output coming from, as that doesn’t look like the console log?

The console log output in Newman should show the same details as the UI.