如何在Postman中发送未定义的值?

huangapple go评论69阅读模式
英文:

how to send undefined value in postman?

问题

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

英文:

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

答案1

得分: 3

与node.js或postman无关。 undefined 不是一个有效的JSON值,尽管在JavaScript中是有效的。 你可能可以使用null来代替。

来自官方JSON标准(ECMA-404,第5节)的说明:

undefined 不是一个有效的JSON值,尽管在JavaScript中是有效的。

一个JSON值可以是对象、数组、数字、字符串、true、false或null。

英文:

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.

答案2

得分: 2

你需要在JSON中使用null代替undefined,因为JSON不支持undefined关键字。示例:

{
  "a": [null, {"b": "ball", "c": "cat"}]
}
英文:

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

huangapple
  • 本文由 发表于 2023年1月3日 21:18:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/74993906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定