# Json array handling different in Newman than Postman App?

**URL:** <https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [October 21, 2019, 7:05pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484 "2019-10-21T19:05:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jilllancaster](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jilllancaster](https://community.postman.com/u/jilllancaster)\
**Post date:** [October 21, 2019, 7:05pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/1 "2019-10-21T19:05:34Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-help-category/38) before creating a new topic.**

Javascript array.push command produces different results when run in Postman App vs Newman Command Line.

Right now I have tempBody defined as:

`var tempBody = {};`

• Then set to `tempBody = pm.request.body;` if `request.body` has content.  
• Or set to `tempBody = {"mode":"NoBody"};` if no request body.

Once set I create an element in the array as follows.

• `tempArray.push({"reqName":pm.info.requestName, "reqUrl":pm.request.url, "reqBody":tempBody});`

I then add it as an updated environment value:  
• `pm.environment.set("compareArray", tempArray);`

In postman app, this statement:  
`console.log("my tempArray is : ", tempArray);`

Produces the following, which includes the Body whether it exists or not. However, when I export and run this script in newman, the reqBody element is missing from the array of json objects.

See an example at the bottom.

```
Array:[]
	0:{}
	reqBody:{}
	mode:"urlencoded"
	urlencoded:[]
	0:{}
	key:"……."
	value:"……."
	1:{}
	key:"…….."
	value:"……."
	2:{}
	key:"…….."
	value:"……"
	reqName:"Get Token for Tests"
	reqUrl:{}
	host:[]
	0:"{{baseUrl}}"
	path:[]
	0:"v3"
	1:"tokens"
	query:[]
	variable:[]
	1:{}
	reqBody:{}
	mode:"NoBody"
	reqName:"FolderEnd"
	reqUrl:{}
	host:[]
	0:"{{baseUrl}}"
	path:[]
	0:"v3"
	1:"mymixchannels"
	query:[]
	variable:

```

When the same script is run in newman command line:

```
{
      "type": "any",
      "value": [
        {
          "reqName": "Get Token for Tests",
          "reqUrl": {
            "path": [
              "v3",
              "tokens"
            ],
            "host": [
              "{{baseUrl}}"
            ],
            "query": [],
            "variable": []
          },
          "reqBody": {
            "mode": "urlencoded",
            "urlencoded": [
              {
                "key": "……….",
                "value": "………."
              },
              {
                "key": "……….",
                "value": "………."
              },
              {
                "key": "………",
                "value": "…………"
              }
            ]
          }
        },
        {
          "reqName": "FolderEnd",

// *******There is no "reqBody" here***********

          "reqUrl": {
            "path": [
              "v3",
              "mymixchannels"
            ],
            "host": [
              "{{baseUrl}}"
            ],
            "query": [],
            "variable": []
          }
        }
      ],
      "key": "compareArray"
    },

```

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [October 23, 2019, 9:06am UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/2 "2019-10-23T09:06:40Z")

</div>

Would you mind sharing the actual code?  
It looks like `reqBody` is present in some of the newman output so I’m thinking it may be the condition checking if there’s a request body that may be incorrect.

---

<div class="post-metadata">

**Author:** ![jilllancaster](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jilllancaster](https://community.postman.com/u/jilllancaster)\
**Post date:** [October 23, 2019, 1:23pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/3 "2019-10-23T13:23:13Z")

</div>

Arlemi,  
Thanks for the response. Below is a cut and paste of the PreRequest script. It is a prototype collection which has only two requests in it. The first Request has a Body. The second Request does not. The body is shown correctly in both Postman App and Newman/Nodejs console log for the first request which has a Body. However, for the second request which has no Body, I add a “dummy” body. The dummy body shows up in the Postman console log however, not in the Newman/Nodejs console log .

I updated the the output from the Postman console log and Newman/Nodejs console log to make sure it matches the prerequest script because I have tried multiple options which all end up with the same results.

Do Postman and Newman command line use the same package for parsing JSON? If you need to see the actual collection, please let me know how to upload and I will do that.

Thanks again,  
Jill

## POSTMAN PREREQUEST:

var mddbCollection = pm.variables.get(“testCollectionVariable”);

pm.environment.set(“requestAccept”, pm.variables.get(“responseContent”));

var tempArray = ;  
var testArray = ;

if (!pm.environment.get(“compareArray”)){  
console.log(“EMPTY”);  
}  
else {  
console.log(“GET CONTENTS”);  
tempArray = pm.environment.get(“compareArray”);  
}

console.log(" stringify body", JSON.stringify(pm.request.body));  
console.log(" stringify name “, JSON.stringify(pm.info.requestName));  
console.log(” stringify url", JSON.stringify(pm.request.url));  
var tempBody = {};

if (JSON.stringify(pm.request.body) === “{}”){  
console.log(“EMPTY”);  
tempBody = {“mode”:“NoBody”};  
}  
else {  
console.log(“HAS A BODY”);

}

testArray.push({“reqBody”:tempBody, “reqName”:pm.info.requestName, “reqUrl”:pm.request.url});  
console.log(“my testArray is : “, testArray);  
console.log(” \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”);

tempArray.push({“reqBody”:pm.request.body, “reqName”:pm.info.requestName, “reqUrl”:pm.request.url});  
console.log(“my tempArray is : “, tempArray);  
console.log(” \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”);

pm.environment.set(“compareArray”, tempArray);  
console.log(“my compareArray is : “, pm.environment.get(“compareArray”));  
console.log(” \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”);

* * *

## POSTMAN PREREQUEST CONSOLE LOG:

GET CONTENTS

09:01:47.447

stringify body

09:01:47.450

{}

stringify name

09:01:47.453

“FolderEnd”

stringify url

09:01:47.455

{“path”:[“v3”,“mymixchannels”],“host”:["{{baseUrl}}"],“query”:,“variable”:}

EMPTY

09:01:47.456

my testArray is :

09:01:47.458

- 
  - Array:
    - 0:{}
      - reqBody:{}
        - mode:“NoBody”

      - reqName:“FolderEnd”
      - reqUrl:{}
        - host:
          - 0:"{{baseUrl}}"

        - path:
          - 0:“v3”
          - 1:“mymixchannels”

        - query:
        - variable:

* * *

09:01:47.459

my tempArray is :

09:01:47.461

- 
  - Array:
    - 0:{}
      - reqBody:{}
        - mode:“urlencoded”
        - urlencoded:
          - 0:{}
            - key:“grant\_type”
            - value:"…"

          - 1:{}
            - key:"…"
            - value:"…"

          - 2:{}
            - key:"…"
            - value:"…"

      - reqName:“Get Token for Tests”
      - reqUrl:{}
        - host:
          - 0:"{{baseUrl}}"

        - path:
          - 0:“v3”
          - 1:“tokens”

        - query:
        - variable:

    - 1:{}
      - reqBody:{}
      - reqName:“FolderEnd”
      - reqUrl:{}
        - host:
          - 0:"{{baseUrl}}"

        - path:
          - 0:“v3”
          - 1:“mymixchannels”

        - query:
        - variable:

* * *

09:01:47.463

my compareArray is :

09:01:47.465

- 
  - Array:
    - 0:{}
      - reqBody:{}
        - mode:“urlencoded”
        - urlencoded:
          - 0:{}
            - key:“grant\_type”
            - value:"…"

          - 1:{}
            - key:“username”
            - value:"…"

          - 2:{}
            - key:"…"
            - value:"…"

      - reqName:“Get Token for Tests”
      - reqUrl:{}
        - host:
          - 0:"{{baseUrl}}"

        - path:
          - 0:“v3”
          - 1:“tokens”

        - query:
        - variable:

    - 1:{}
      - reqBody:{}
      - reqName:“FolderEnd”
      - reqUrl:{}
        - host:
          - 0:"{{baseUrl}}"

        - path:
          - 0:“v3”
          - 1:“mymixchannels”

        - query:
        - variable:

* * *

09:01:47.466

* * *

## NEWMAN CONSOLE LOG:

│ 'my tempArray is : ‘, [ { reqName: ‘Get Token for  
│ Tests’,  
│ reqUrl:  
│ { path: [‘v3’, ‘tokens’],  
│ host: [‘{{baseUrl}}’],  
│ query: ,  
│ variable: },  
│ reqBody:  
│ { mode: ‘urlencoded’,  
│ urlencoded:  
│ [ { key: ‘grant\_type’, value: ‘…’ },  
│ { key: ‘username’, value: ‘…’ },  
│ { key: ‘password’, value: ‘…’ } ] } }  
│ ,  
│ { reqName: ‘FolderEnd’,  
│ reqUrl:  
│ { path: [‘v3’, ‘mymixchannels’],  
│ host: [‘{{baseUrl}}’],  
│ query: ,  
│ variable: } } ]  
│ ’ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*’  
│ 'my compareArray is : ‘, [ { reqName: ‘Get Token  
│ for Tests’,  
│ reqUrl:  
│ { path: [‘v3’, ‘tokens’],  
│ host: [‘{{baseUrl}}’],  
│ query: ,  
│ variable: },  
│ reqBody:  
│ { mode: ‘urlencoded’,  
│ urlencoded:  
│ [ { key: ‘grant\_type’, value: ‘…’ },  
│ { key: ‘username’, value: ‘…’ },  
│ { key: ‘password’, value: ‘…’ } ] } }  
│ ,  
│ { reqName: ‘FolderEnd’,  
│ reqUrl:  
│ { path: [‘v3’, ‘mymixchannels’],  
│ host: [‘{{baseUrl}}’],  
│ query: ,  
│ variable: } } ]  
│ ’ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*’  
└

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [October 23, 2019, 2:24pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/4 "2019-10-23T14:24:06Z")

</div>

Can you try replacing this condition

```auto
if (JSON.stringify(pm.request.body) === “{}”){

```

with

```auto
if (!pm.request.body){

```

If this doesn’t work, sharing your collection will be handy yes, you can get a shareable link to your collection from Postman, as explained on the following link:

[https://learning.getpostman.com/docs/postman/collections/sharing\_collections/#sharing-collections-in-the-app](https://learning.getpostman.com/docs/postman/collections/sharing_collections/#sharing-collections-in-the-app)

---

<div class="post-metadata">

**Author:** ![jilllancaster](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jilllancaster](https://community.postman.com/u/jilllancaster)\
**Post date:** [October 23, 2019, 4:57pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/5 "2019-10-23T16:57:50Z")

</div>

if (!pm.request.body) {  
had the same results. Both commands successfully determine that pm.request.body is null.

The issue is related solely to adding a properties to a JSON object then being able to print/log all the objects correctly from the Postman App.

When the collection is exported and run using Newman, the exact same statements successfully print the properties which were set to postman values **HOWEVER NEWMAN DOES NOT PRINT**  
or show the properties in the JSON object which were set locally in the script. i.e.,

**when** :

- tempBody = {“mode”:“NoBody”}; it does not show up in the newman log when the following statements are executed.

**when** :

- those same properties are set to postman values (i.e, the pm.request.body exists) then when the following command is run the properties **DO** show up in the Newman Console log.

As is I can’t share the collection due to the collection containing passwords, etc. I will need to build a dummy collection before sharing.

---

<div class="post-metadata">

**Author:** ![jilllancaster](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jilllancaster](https://community.postman.com/u/jilllancaster)\
**Post date:** [October 23, 2019, 5:11pm UTC](https://community.postman.com/t/json-array-handling-different-in-newman-than-postman-app/8484/6 "2019-10-23T17:11:57Z")

</div>

Cause of the problem is found! Postman export is not setting “disableBodyPruning”: true

> <https://github.com/postmanlabs/newman/issues/1880>
>
> \*\*Describe the bug\*\*
> Newman CLI ignores the "Body" section of a GET request. In… other words, Newman does not "process" the Body section (otherwise known as request.data) of a GET request but the Postman desktop app does.
> 
> \*\*To Reproduce\*\*
> Steps to reproduce the behavior:
> 1. Install Postman desktop app 6.7.2 (macOS)
> 2. Install Newman 4.3.1 package via npm (macOS)
> 3. Create a GET request in Postman desktop app
> 4. Include a JSON in the Body of the request (I understand that the ability to do this for a GET request is new)
> 5. Ensure that the JSON is compatible with the GET request. This means that the Body of the GET request will need information that augments what is returned in the response.
> 6. Create a test to assert on the response body
> 7. Note that the assertion passes in the Postman desktop app
> 8. Run the collection in Newman
> 9. Notice that a TypeError or some other failure related to the passing assertion made in the Postman desktop app will return in Newman
> 
> \*\*Expected behavior\*\*
> The assertion should pass in both Postman and Newman
> 
> \*\*Screenshots\*\*
> !\[passes-in-postman\](https://user-images.githubusercontent.com/20306765/52157785-cec39080-2646-11e9-8d07-10a739d091a0.png)
> !\[fails-in-newman\](https://user-images.githubusercontent.com/20306765/52157786-d08d5400-2646-11e9-8d0b-aaa9fb4d736e.png)
> 
> 
> 
> \*\*App information (please complete the following information):\*\*
> - Native App
> - Postman Version 6.7.2
> - Newman 4.3.1
> - macOS High Sierra 10.12.6
> 
> \*\*Additional context\*\*
> Willing to set up a meeting with a Postman developer but will not share the endpoint that this was tested on here

In my exported postman collection I found the following  
“protocolProfileBehavior”: {}

I changed that parameter as per the issue suggestion above to:  
“protocolProfileBehavior”: {  
“disableBodyPruning”: true  
}

npm list newman  
shows:  
newman@4.5.5
