Booleans and Null
Learning Focus
true, false, and null look trivial but cause frequent bugs when languages apply different coercion semantics.
Boolean
Written in lowercase only — capitals cause a parse error.
{
"isActive": true,
"isDeleted": false,
"hasAccess": true
}
Language Mapping
| JSON | Python | JavaScript | Go | PHP |
|---|---|---|---|---|
true | True | true | true | true |
false | False | false | false | false |
Null
Represents the intentional absence of a value. Also lowercase only.
{ "middleName": null, "deletedAt": null }
null vs Missing Key
{ "a": null } // key exists, value is null
{ } // key does not exist at all
These are semantically different. Handle both cases explicitly:
data = {"a": None}
print("a" in data) # True — key present, value null
print("b" in data) # False — key truly missing
Type Coercion Traps (JavaScript)
// ⚠️ Dangerous: loose equality
if (!apiResponse.value) {
// Triggers for null, false, 0, "" — not just null!
}
// ✅ Safe: explicit check
if (apiResponse.value === null) { /* ... */ }
if (apiResponse.value === false) { /* ... */ }
Concept Map
Concept Flow
JSON Literals
├── true / false — lowercase only (parse error otherwise)
└── null — lowercase only
└── null ≠ missing key ≠ empty string ≠ 0
Common Pitfalls
| Pitfall | Consequence | Prevention |
|---|---|---|
True / False in raw JSON | Parse error | Use lowercase in JSON strings |
Treating null as missing key | Logic errors | Check key existence separately |
Coercing 0 / "" to boolean | Silent logic bugs | Use strict equality |
Python None via f-string | Produces "None" string, not null | Always use json.dumps() |
What's Next
- Previous: Strings and Numbers — Review primitive types.
- Next: JSON Objects — The key-value container type.
- Section Overview — Return to the Data Types module index.