undefined is not valid JSON
`undefined` is a JavaScript value with no JSON equivalent. `JSON.stringify` normally drops undefined object properties, so seeing it in a document means the JSON was built by string concatenation rather than serialised.
The input
{"a": undefined}{"a": null}How to fix it
Use `null` for an intentionally empty value, or omit the key entirely.
`JSON.stringify({a: undefined})` returns `{}` — if you are seeing `undefined` in the text, something built that string by hand.
What each parser reports
Every message below was captured by running this exact input through the parser named. 17 of 21 parsers rejected it; 4 accepted it.
| Parser | Exact message |
|---|---|
| CPython json.loads CPython 3.12.3 | Expecting value: line 1 column 7 (char 6)what this message means → |
| encoding/json Unmarshal Go go1.22.2 | invalid character 'u' looking for beginning of valuewhat this message means → |
| Gson Java 21.0.12 | accepted — no error |
| Gson JsonParser (lenient off) Java 21.0.12 | accepted — no error |
| hjson Node.js 22.22.2 | End of input while parsing an object (missing '}') at line 1,16 >>>"a": undefined} ...what this message means → |
| Jackson ObjectMapper Java 21.0.12 | Unrecognized token 'undefined': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')what this message means → |
| JavaScriptCore JSON.parse JavaScriptCore (Bun 1.4.1) | JSON Parse error: Unexpected identifier "undefined"what this message means → |
| json-bigint Node.js 22.22.2 | Unexpected 'u' |
| JSON5 Node.js 22.22.2 | JSON5: invalid character 'u' at 1:7what this message means → |
| JSON::PP Perl 5.038002 | malformed JSON string, neither array, object, number, string or atom, at character offset 6 (before "undefined}")what this message means → |
| json_decode PHP 8.3.6 | Syntax error |
| Newtonsoft.Json JsonConvert Newtonsoft.Json 13.0.3 on .NET 8.0.30 | accepted — no error |
| Newtonsoft.Json JsonTextReader Newtonsoft.Json 13.0.3 on .NET 8.0.30 | accepted — no error |
| orjson CPython 3.12.3 | unexpected character, expected a JSON value: line 1 column 7 (char 6)what this message means → |
| Ruby JSON.parse Ruby 3.2.3 | unexpected token at '{"a": undefined}' |
| serde_json::from_str Rust (serde_json 1.x) | expected value at line 1 column 7what this message means → |
| SpiderMonkey JSON.parse SpiderMonkey 115 | JSON.parse: unexpected character at line 1 column 7 of the JSON datawhat this message means → |
| System.Text.Json Deserialize .NET 8.0.30 | 'u' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 6.what this message means → |
| System.Text.Json JsonDocument .NET 8.0.30 | 'u' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 6.what this message means → |
| ujson CPython 3.12.3 | Expected object or value |
| V8 JSON.parse Node.js 22.22.2 | Unexpected token 'u', "{"a": undefined}" is not valid JSONwhat this message means → |
What the specification says
The exact sections that govern this error. Descriptions are our paraphrase; follow the links for the normative text.
| Body | Section |
|---|---|
| IETF | A value must be an object, array, number, string, or one of the three literal names, which the section states must be lowercase. No other literal names are allowed. |
| Ecma International | Lists the six structural tokens, the three literal name tokens, and the four whitespace code points. Whitespace is not allowed within a token. |
Other errors in this category
NaN is not valid JSON
`NaN` has no representation in JSON. It appears when a language serialises a floating-point not-a-number without checking — Python…
Infinity is not valid JSON
Same root cause as NaN — a float overflowed and the serialiser wrote `Infinity` or `-Infinity`, which the JSON grammar has no toke…
Python True / False / None in JSON
Python's `repr` of a dict writes `True`, `False` and `None`. JSON requires the lowercase `true`, `false` and `null`.…