# I want to set null to an entity in the request body

**URL:** <https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488>\
**Category:** Help Hub\
**Tags:** collections, json\
**Created:** [February 9, 2024, 7:29am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488 "2024-02-09T07:29:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aviation-astronomer8](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@aviation-astronomer8](https://community.postman.com/u/aviation-astronomer8)\
**Post date:** [February 9, 2024, 7:29am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488/1 "2024-02-09T07:29:26Z")

</div>

Hi Team,

I need your help in Postman Automation. Please find the body below. I want to replace account number array with null for some testcases.

during run time. If you guys any idea, Please help me.

```auto
{
    "accountid":12345,
    "accountnumber": ["123456789"],
    "accountname":"myaccount"
}

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [February 9, 2024, 9:47am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488/2 "2024-02-09T09:47:37Z")

</div>

Hey @aviation-astronomer8 👋

Welcome to the Postman Community! :postman:

How are you running this? Is it data driven through the Collection Runner or CLI?

Is the `accountnumber` always an array?

If you can provide more context to the question, that will help folks to help you. 🙏

---

<div class="post-metadata">

**Author:** ![aviation-astronomer8](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@aviation-astronomer8](https://community.postman.com/u/aviation-astronomer8)\
**Post date:** [February 9, 2024, 10:03am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488/3 "2024-02-09T10:03:54Z")

</div>

The account number is always String format but here it will accept only in array format.  
I am getting data driven from csv file to collection Runner.

The Api will get data by passing either account id, account number, account name.

But when I am passing “pm.variables.set(“accountNumber”,null)”. it is setting the null as string. I want to replace that entire array as null.

{

“accountId”:{{accID}},

“accountNumber”: [“{{accNumber}}”],

“accountName”:“{{accName}}”

}

This is how my body will looks like.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 9, 2024, 10:33am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488/4 "2024-02-09T10:33:30Z")

</div>

Not tested, but it will be something like.

```auto
if (data.accountNumber === "null") {
    const body = JSON.parse(pm.request.body.raw);
    body.accountNumber = null
    pm.request.body.raw = body
}

```

This needs to go in the pre-request script.

data is a special variable which contains the data for the current iteration. So you should be able to have conditional statement checking for the accountNumber === “null”. The string.

You can then parse the current request body, update the account number to be the correct type of null, and then resave the body which will then be used in the request.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 10, 2024, 10:34am UTC](https://community.postman.com/t/i-want-to-set-null-to-an-entity-in-the-request-body/57488/5 "2024-03-10T10:34:21Z")

</div>

Closed on March 10, 2024, 10:34am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
