JSON Null & Boolean Values: When and How to Use Them
Null and boolean are two of JSON's most misunderstood types. This guide clarifies when to use them, how they differ from similar concepts in programming languages, and the mistakes to avoid.
JSON Boolean Values
JSON has exactly two boolean values: true and false. They must be lowercase — no quotes, no capitalization. Booleans represent binary states: yes/no, on/off, enabled/disabled.
{
"isActive": true,
"isVerified": false,
"hasSubscription": true,
"emailOptIn": false,
"darkMode": true
}Boolean Naming Conventions
Good boolean field names read naturally as questions. Prefix them with is, has, can, or should to make their meaning clear:
{
"isEnabled": true,
"hasPermission": false,
"canEdit": true,
"shouldNotify": false,
"isPublished": true
}Avoid ambiguous names like "status": true— it's unclear what "true status" means. "isActive": true is immediately understandable.
Invalid Boolean Formats
These are all invalid in JSON and will cause parse errors:
// ❌ All of these are INVALID JSON
{
"a": True, // Capital T — must be lowercase
"b": FALSE, // All caps — must be lowercase
"c": "true", // Quoted — this is a string, not a boolean
"d": 1, // Number — JSON has no truthy/falsy concept
"e": yes // Not a JSON type at all
}In JSON, "true" (with quotes) is a string containing four characters, not a boolean. Many bugs come from accidentally quoting boolean values. A consumer checking if (data.isActive === true) will get false when the value is the string "true".
JSON Null Values
The null value represents an intentional absence of data. It is always lowercase and unquoted:
{
"user": {
"id": 42,
"name": "Jane Doe",
"middleName": null,
"phone": null,
"deletedAt": null,
"referredBy": null
}
}In this example, middleName is nullbecause the user doesn't have one, phone hasn't been provided yet, and deletedAt is nullbecause the account hasn't been deleted. Each null conveys "this field exists but currently has no value."
Null vs Undefined vs Missing Keys
This distinction trips up many developers. JSON only has null — it does not have undefined. But there are three different ways a value can be "absent":
// 1. Key present with null value — "exists but empty"
{
"phone": null
}
// 2. Key missing entirely — "not provided"
{
}
// 3. Key present with empty string — "provided but blank"
{
"phone": ""
}These three states have different semantic meanings:
null— the field is known but has no value. The user explicitly left it empty or it was cleared.- Missing key— the field was not included in the response. This might mean the consumer doesn't have permission to see it, or the API version doesn't include it.
- Empty string
""— the field has a value, and that value is an empty string. This is a valid string, not absence.
The String "null" Trap
Watch out for the difference between null and "null":
{
"correctNull": null,
"stringNull": "null",
"stringUndefined": "undefined"
}The value "null" is a string containing four characters. It is not the same as null. This commonly happens when code serializes a null value incorrectly, converting it to the string "null" before inserting it into JSON.
Using Null and Booleans Together
A practical example showing both types working together in a feature flag system:
{
"features": {
"darkMode": {
"enabled": true,
"rolloutPercentage": 100,
"overrideUserId": null
},
"betaSearch": {
"enabled": false,
"rolloutPercentage": 0,
"overrideUserId": null
},
"newCheckout": {
"enabled": true,
"rolloutPercentage": 25,
"overrideUserId": 1042
}
}
}Here, enabled is a boolean controlling whether the feature is on, rolloutPercentage is a number for gradual rollout, and overrideUserId is either a specific user ID or nullwhen there's no override.
Common Mistakes to Avoid
- Capitalizing booleans:
True,False,TRUE,FALSEare all invalid. Only lowercasetrueandfalsework. - Quoting null or booleans:
"null"and"true"are strings, not the actual null and boolean types. - Using 0/1 for booleans: JSON supports real booleans. Don't use
0and1as substitutes — they're numbers. - Confusing null with undefined:
undefinedis not a valid JSON value. If you serialize a JavaScript object withundefinedproperties, they are silently dropped. - Inconsistent null handling: Decide whether missing fields in your API responses should return
nullor be omitted entirely, then follow that convention everywhere.
Try it yourself: Paste your JSON into our JSON Validator to check that your null and boolean values are correctly formatted.