In JSON, null says that a value is empty on purpose: the key is there, but it holds nothing. You write it as the word null in lowercase, with no quotes around it.
Every command and output on this page is real, run with jq 1.8.2 on macOS.
Syntax
"key": null
"key": the name, in double quotes like every JSON key.null: the empty value, in lowercase and without quotes. It can stand wherever a JSON value can, in an object or in an array.
See section 3 of RFC 8259 (opens in a new tab), the JSON standard: the three literal names false, null and true must be lowercase.
Prerequisites
- jq, to check the JSON. Install it from the jq download page (opens in a new tab).
The Example
A contact with a name and no phone number yet, saved in a file named contact.json.
Step 1: Write the JSON
{"name": "Asha", "phone": null}
Step 2: Check It with jq
jq . reads the file and prints it back neatly. If the JSON were broken, jq would stop with an error instead:
jq . contact.json
{
"name": "Asha",
"phone": null
}
Step 3: Read the Value
jq '.phone' contact.json
null
.phone picks the value of the key phone: the key is there, and its value is null.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing it in capitals: "phone": NULL | jq stops: jq: parse error: Invalid numeric literal at line 1, column 31 | Write null in lowercase |
Putting it in quotes: "phone": "null" | It’s a string of four letters: jq '.phone' prints "null" with quotes | Leave out the quotes |
FAQ
Is null the same as an empty string?
No. An empty string, "", is text with nothing in it. null isn’t text at all, which is why "null" in quotes counts as a string.
Where will I see null?
Often in answers from web APIs, for a value that has nothing in it yet. For example, n8n’s API ends a list of workflows with "nextCursor":null when there is no next page.
Conclusion
Write null in lowercase and without quotes wherever a value is empty on purpose. NULL breaks the JSON, and "null" in quotes is just text.
0 comments