SunAns
SunAns

Reputation: 313

how to send undefined value in postman?

Is there a way to send something like this in postman?

{
 "a": [undefined, {"b":"ball", "c":"cat"}]
}

Postman gives a red underline under undefined. If I use the pre-request script to pm.variables.set('undefinedVariable', undefined); and use this, then my code is giving this error

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Invalid request payload JSON format"
}

Upvotes: 2

Views: 2601

Answers (2)

so-random-dude
so-random-dude

Reputation: 16585

It has nothing to do with node.js nor postman. undefined is not a valid json value even though it is valid in javascript. You may be able to use null instead

https://stackoverflow.com/a/14946821/6785908

  • undefined is not a valid JSON value, even though it is valid in javascript.

    From the official JSON standard (ECMA-404, Section 5):

    A JSON value can be an object, array, number, string, true, false, or null.

Upvotes: 4

Arpan Patnaik
Arpan Patnaik

Reputation: 59

You need to define null in place of undefined as JSON doesn't handle undefined keyword. Example: { "a": [null, {"b":"ball", "c":"cat"}] }

Upvotes: 2

Related Questions