The null value is used when a key does not have a value.
It acts as a placeholder, meaning the key exists, but there is no information stored for it yet.
For example, a person's middle name may not be known, or a phone number may not have been added yet.
{
"name": "Emma",
"middleName": null,
"age": 14
}
In this example:
"name" has the value "Emma"."middleName" has the value null, which means no middle name has been provided."age" has the value 14.The value null must not be inside quotation marks.
✅ Correct
{
"phoneNumber": null
}
❌ Wrong
{
"phoneNumber": "null"
}
Why is it wrong? "null" is just the text "null". It is not the special JSON value null.
Use null when a value is missing, unknown, or has not been set yet.
✅ Correct
{
"email": null
}
This means the email address has not been provided.
❌ Wrong
{
"email":
}
Why is it wrong? Every key in JSON must have a value. If there is no value, use null.
A null value can be updated when the information becomes available.
Before
{
"favoriteColor": null
}
After the user chooses a color
{
"favoriteColor": "Blue"
}
This shows how null acts as a temporary placeholder until a real value is added.
| Value | Meaning |
|---|---|
null | The key exists, but it currently has no value. |
"null" | The word "null" stored as text (a string). |
null without quotation marks.null when a value is missing or unknown.null is a placeholder that can be replaced with a real value later.null instead.