Null Values in JSON: Validity, Representation and Formatting Pitfalls
Yes, null is a valid JSON value. Learn how to write it, how it differs from missing keys and the string "null", and what formatting or copying can break.
Null is a valid JSON value. The JSON grammar, defined in ECMA-404 and RFC 8259, lists exactly three literal names: true, false and null. Any place a value is allowed, including an object member, an array element or the entire document, can hold null. The rest of this article covers how to write null correctly, how it differs from look-alike alternatives, and whether formatting, validation or copying tools keep its meaning intact.
How to write null in JSON
Null is written as the bare, lowercase word null with no quotation marks. The literal is case-sensitive, so Null, NULL and nil are not valid JSON and a conforming parser will reject them.
{
"middleName": null,
"tags": ["a", null, "c"],
"address": {
"line2": null
}
}
A document consisting only of null is also valid under RFC 8259 and ECMA-404. The older RFC 4627 required the top level to be an object or array, so some older or stricter tools may still reject a bare top-level null. Check the specific parser if this matters to you.
null
What null means compared with similar-looking alternatives
The JSON specification defines null only as a value. It does not say what null means in your application. In practice, the following forms are distinct and should not be treated as interchangeable unless your schema or API says so:
- "field": null means the key is present and its value is explicitly null.
- An omitted key means the key is absent. Many APIs read this as "not provided" or "leave unchanged" rather than "clear this value."
- "field": "null" is a four-character string. It is not the null literal.
- "field": "" is an empty string.
- "field": [] or "field": {} is an empty array or object.
Object keys cannot be null. JSON requires every key to be a quoted string, so { null: 1 } is invalid. { "null": 1 } is valid, but its key is just the string "null".
How null maps into common languages
Parsers translate null into each language's own empty-value concept. JavaScript's JSON.parse returns null. Python's json module returns None and writes None back out as null. Other languages map it to their own null, nil or optional-empty type.
The reverse direction is where meaning most often shifts. In JavaScript, JSON.stringify behaves as follows:
- NaN and Infinity have no JSON equivalent, so they become null.
- undefined is dropped entirely when it is an object property value.
- undefined becomes null when it is an array element.
JSON.stringify({ a: undefined, b: NaN, c: [undefined] })
// → {"b":null,"c":[null]}
As a result, a null in the output may have started as something else, and a missing key may have started as undefined. Many serializers in other ecosystems also offer settings that omit null-valued fields. If your consumer treats "absent" and "null" differently, confirm how your serializer is configured.
What formatting and validation tools change
In a developer-tools context, "formatting" JSON means changing whitespace: pretty-printing with indentation or minifying to a single line. Whitespace outside strings has no meaning in JSON, so a correct formatter changes only spacing and line breaks and should leave every null exactly where it was. Validation checks syntax and does not alter the stored characters.
Some tools do more than reformat:
- "Remove empty" or "clean up" options may delete null-valued keys, which turns an explicit null into an absent key.
- Key sorting reorders members. This is harmless to JSON semantics but can make diffs confusing.
- Tools that round-trip data through another format, such as YAML, CSV or a spreadsheet, may turn null into an empty cell, the text "null", or a format-specific marker such as ~ in YAML.
- Schema validators may reject null unless the schema explicitly allows it, for example by including "null" in a JSON Schema type list.
The word "font" or "style" can also be ambiguous here. Changing how null is displayed, such as syntax-highlight colors in an editor or a monospace font in CSS, is purely visual and leaves the data unchanged. Replacing the letters with Unicode look-alike characters, such as mathematical bold or full-width letters, changes the stored code points. The result is no longer the null literal and will fail to parse. Reversing or mirroring text has no legitimate role in JSON data. A reversed "llun" is simply invalid.
Will null survive copying and sharing?
Because null is plain ASCII with no quotes, it avoids the smart-quote substitution that often breaks JSON strings pasted through word processors or chat apps. The surrounding structure is still exposed to that substitution, though. Other risks to the literal itself include:
- Autocorrect or sentence-case features capitalizing it to Null when it appears at the start of a line.
- Rich-text editors inserting invisible characters such as non-breaking spaces or zero-width characters near it.
- Translation or text-styling tools rewriting it as a word rather than a keyword.
No destination-specific tests were supplied for this article, so behavior in a particular chat app, editor or document tool is unverified. The reliable check is to paste the result back into a validator before relying on it.
For accessibility and search, plain null is ordinary text. Assistive technology will typically encounter it as the word "null." No specific screen reader behavior was tested for this article. Searching a codebase for null will also match the string "null" and words containing it, such as "nullable," so use a JSON-aware query tool when you need only true null values. Styled Unicode look-alikes defeat both text search and predictable screen reader output. When JSON appears in documentation, keep it as plain text in a code block.
Recommendation
Use the lowercase, unquoted null literal whenever you need to state explicitly that a value is empty or unknown. Use plain whitespace formatting and syntax validation freely, since both preserve null. The decisive tradeoff is that null and an absent key are different signals: choose one convention, document it, and avoid any tool option, serializer setting or format conversion that silently swaps one for the other.
Plain, unstyled text is the right choice whenever JSON will be parsed, copied into another system, searched or read with assistive technology. Visual styling belongs in the editor or the page's presentation layer, not in the characters themselves.