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

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.

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

Hey @aviation-astronomer8 :wave:

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. :pray:

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.

Not tested, but it will be something like.

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.