Home > Back-end >  how to send undefined value in postman?
how to send undefined value in postman?

Time:01-04

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"
}

CodePudding user response:

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.

CodePudding user response:

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

  • Related