How to Write null in JSON
To say that a pair has no value in JSON, write null as its value: lowercase and without quotes, as in "phone": null. It isn't the same as an empty string, false, the text "null" or a pair that's left out, and this guide shows each difference with jq.
Syntax
null
null: the value for "no value", written in lowercase letters with no quotes around it.
The JSON standard, RFC 8259, counts null as a type of its own: JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays). It's written as one of three literal names, with true and false, and The literal names MUST be lowercase. No other literal names are allowed.
The Example
A file called contact.json describes a contact with two pairs: a name, Ada, and a phone with no value, which is null. jq, a command-line JSON tool, checks that the file is valid and shows the type of the value.
Prerequisites
- jq, to check the file. Run
jq --versionto see which one you have; this guide uses jq 1.8.2 (Download jq).
Step 1: Write the null Value
Create a file called contact.json with this text:

{
"name": "Ada",
"phone": null
}
The phone pair is in the file, but its value is null.
Step 2: Check It with jq
In a terminal, in the folder with the file, run:
jq . contact.json
jq's manual explains the .: the . program's main use is to validate and pretty-print the inputs. The file was valid, and jq printed null back as it is, without quotes:
{
"name": "Ada",
"phone": null
}
Step 3: Check the Value's Type
Run:
jq '.phone | type' contact.json
"null"

.phone reads the value of phone, and | hands it on to type. jq's manual: The type function returns the type of its argument as a string, which is one of null, boolean, number, string, array or object. So the value's type is null, a type of its own. The quotes in the output are there because type answers with the type's name as text.
null Is Not "", false or "null"
look-alikes.json puts null next to three values that are easy to mix up with it:
{
"null_value": null,
"empty_string": "",
"false_value": false,
"null_in_quotes": "null"
}
jq 'map_values(type)' look-alikes.json
{
"null_value": "null",
"empty_string": "string",
"false_value": "boolean",
"null_in_quotes": "string"
}
map_values(type) swapped each value for the name of its type and kept the names of the pairs; the manual says map_values outputs an array if given an array, or an object if given an object. Only the first value is null. "" is a string with no characters, false is a boolean, a true/false value, and "null" in quotes is text: the four letters n, u, l, l.
null Is Not a Left-Out Pair
no-phone.json leaves the phone pair out:
{
"name": "Ada"
}
Reading phone from both files gives the same answer:
jq '.phone' contact.json no-phone.json
null
null
jq read both files. Its manual says the values it reads are passed through the provided filter one at a time, so it printed one result per file. The manual calls a name a key, and says that .foo, here .phone, produces the value at the key "foo" if the key is present, or null otherwise. That's why no-phone.json gave null too. has tells the two apart:
jq 'has("phone")' contact.json no-phone.json
true
false
The manual: The builtin function has returns whether the input object has the given key, or the input array has an element at the given index. The first answer, true, is for contact.json, which has a phone pair whose value is null. The second, false, is for no-phone.json, which has no phone pair at all.
Common Mistakes
I wrote Null with a capital letter in a copy of contact.json and ran jq . on it. jq 1.8.2 said:
jq: parse error: Invalid numeric literal at line 4, column 0
jq didn't recognise Null and tried to read it as a number, which is why the message mentions one. It points at line 4, column 0, just after the line with Null, because jq checks a word once it reaches the end of it.
| Mistake | What happens | Do this instead |
|---|---|---|
A capital letter, Null or NULL | Invalid numeric literal | Write null |
A word from another programming language: None, nil or undefined | Invalid numeric literal for each of them | Write null |
Quotes, "null" | Valid, but it's text, not null | Leave the quotes out |
Nothing after the colon, "phone": | Unmatched '}' at the closing bracket | Write null, or leave the pair out |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Invalid numeric literal where null should be | A capital letter, or a word such as None | Write null in lowercase |
| Invalid literal | A misspelling such as nul | Write null |
jq prints null for a pair that isn't in the file | .phone gives null for a missing name | Check with has("phone") |
| The value prints with quotes in jq | It's the text "null" | Remove the quotes |
FAQ
Where can null go?
Anywhere a value can: as the value of a pair, inside an array, or as a whole file. jq printed [1, null, 3] back as [1,null,3] with -c, its compact output, and a file that holds only null back as null. A whole file can be one value on its own, because, in the standard's words, A JSON text is a serialized value.
Can a name be null?
No. The standard says A name is a string. A file with { null: "Ada" } laid out over three lines stopped jq with Object keys must be strings.
Should I write null or leave the pair out?
The standard doesn't say; it depends on what the software that reads the file expects. jq read both as null, and only has told them apart.
Conclusion
A pair with no value gets null: lowercase, without quotes. jq showed that its type is null, while "" and "null" are strings and false is a boolean. A left-out pair also read as null in jq, and only has("phone") told the two apart. Null, NULL, None, nil and undefined all stopped jq with Invalid numeric literal.
Additional Resources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format: values and the three literal names.
- Introducing JSON: the format's diagrams, on its original site.
- jq 1.8 manual:
type,has,map_valuesand jq's other filters.
