Every JSON document has two kinds of content: the values that are there, and the spaces where values are not. Those spaces come in exactly three shapes. An explicit null is a property that exists and whose value is declared to be nothing. An empty string — or an empty array or object — is a property that exists and holds a deliberately hollow value. A missing property is a key that the sender simply did not include. Three statements, three different meanings, and yet most client code treats all three as the same event: the field is empty. This guide is about why that habit produces quiet, expensive bugs, and what to do instead.
The failure pattern is always similar. A PATCH request wipes a database column because the client serialized a form object with nulls for every field the user never touched. A profile page renders the literal text null in the middle of a sentence. A configuration flag that a service treats as use-the-default silently becomes zero. None of these produce a stack trace, because nothing crashed: the client asked one question — is there a value? — where three different questions were being answered: Is it unknown? Was it cleared? Was it ever asked?
The Three Absences, Side by Side
JSON, as specified in RFC 8259, gives you exactly one absence token: the literal null. Everything beyond that — empty strings, empty containers, omitted keys — is convention that applications layer on top. To see all three conventions in one place, consider a user record in which each absence appears deliberately:
{
"id": "usr_84c1",
"middleName": null,
"bio": "",
"phoneNumber": "+1 555 0143"
}
and a sibling record in which one of those keys never appears at all:
{
"id": "usr_9f02",
"middleName": null,
"phoneNumber": "+1 555 0188"
}
Read them as statements about the world. In the first record, "middleName": null says the field is part of the schema and its value is unknown or unset. The "bio": "" entry says something stronger: the bio field was actively set to nothing — the user had a bio editor, used it, cleared it, and saved. In the second record, the absence of bio says nothing about bios: the sender omitted the key because it does not apply to this account type, because the server serializes only fields the user has touched, or because the endpoint answers a narrower question than the full profile.
None of these readings can be derived from the JSON itself. The bytes tell you only which shape you are looking at; the meaning comes from the contract between sender and receiver. The same shape can mean unknown for one field and deliberately cleared for another, and only the API design decides.
Unknown, Deliberately Empty, or Not Applicable
A workable mental model assigns one question to each shape. Explicit null answers we looked, and there is no value — unknown, unset, or unavailable. An empty string or container answers we looked, and the value is nothing — a deliberate, known emptiness. An absent property answers this question was not asked of this record — not applicable, optional, or intentionally withheld. Each answer demands different client behavior, which is why collapsing them always loses information.
- null — unknown. The canonical model is SQL's three-valued logic: NULL does not equal NULL, because unknown does not equal anything, including itself. The property exists; the value does not, yet.
- "" — deliberately empty. The value is known, and it is nothing. Someone cleared it. For strings this is often a thin distinction from null; for collections it is loud and important, as the next paragraph explains.
- absent — not applicable. The key is not part of this document. The field may be optional, may not apply to this resource type, or — in a PATCH body — may mean leave this alone.
The distinction earns its keep with containers. An empty array is an answer: I computed the invoice list for this customer, and it has zero entries. A missing array is a non-answer: I did not compute invoices for this customer at all — perhaps they are not eligible, perhaps the endpoint scopes itself narrowly. A client that renders a section for an empty array but hides it when the key is absent has preserved the distinction; a client that falls back to an empty array has silently converted not-computed into computed-and-empty, and the interface now shows an empty panel where it should show nothing. We treat container shapes in depth in Empty Array versus Empty Object.
Formal schemas encode the split with two independent mechanisms. In JSON Schema, null is a type: a nullable property needs its type declared as a list such as ["string", "null"], while a property that may be absent is left out of the required list. Nullability is about values; optionality is about keys. OpenAPI carries the same split with nullable versus the required list. A property marked both nullable and optional may take all three absences — and each needs its own handling on the client.
How Programming Languages Flatten the Distinction
If JSON keeps the three shapes distinct, the runtimes that consume it mostly do not. Each mainstream language flattens the distinction in its own way, and knowing the flattening for your stack is most of the battle. Below are the five you are most likely to meet.
JavaScript: undefined versus null
JavaScript has two absence values: null, which arrives from JSON, and undefined, which is what you get when you read a property that was never present. JSON.parse keeps the distinction intact: an explicit null survives as null, a missing key surfaces as undefined on access. It is the convenience operators that erase it — destructuring defaults treat undefined as absent and null as a real value, while nullish coalescing treats both as no value:
const user = { nickname: null };
// Destructuring default fires only for undefined (absent):
const { nickname = "anonymous" } = user;
// nickname === null — the default did NOT fire
// ?? collapses null and undefined into one bucket:
const name2 = user.nickname ?? "anonymous";
// name2 === "anonymous" — the explicit null was absorbed
Serialization flattens in the other direction: JSON.stringify drops properties whose value is undefined, so an object you reconstruct in memory and re-serialize can lose keys entirely — an explicit null stays null, but an undefined you assigned deliberately turns into an absent property on the wire. Round-tripping a payload through JavaScript is therefore not information-preserving, which matters when you log, cache, or echo payloads back in a PATCH. The footnote that typeof null returns an object is a preserved compatibility bug; it confuses newcomers but says nothing about semantics.
Python: None versus a missing key
Python's json module maps null to None, and a missing key is not None at all — it raises KeyError on subscript access. The flattening happens the moment someone reaches for dict.get() without a sentinel, because get() returns None for both an explicit null and a missing key. Keeping the shapes apart takes a sentinel object:
import json
UNSET = object() # sentinel: no real value can ever be this
payload = json.loads(raw)
bio = payload.get("bio", UNSET)
if bio is UNSET:
... # property absent: the key was never sent
elif bio is None:
... # property present, explicitly null
elif bio == "":
... # property present, deliberately empty
The same collapse appears in Pydantic models: a field typed Optional[str] with a default of None cannot distinguish the sender sent null from the sender never sent the key, unless the model tracks whether the field was set. If your contract depends on that difference — and PATCH contracts always do — the deserialization layer, not your handler code, is where it must be preserved.
Java: Optional and Jackson
Java adds a third absence-like value: Optional.empty. Jackson deserializes an explicit JSON null into a null reference, and a missing property into the field's default — often null again, collapsing the two immediately. The JDK 8 module can populate Optional fields, but an Optional.empty can then mean either the JSON had null or had no such key. When the difference matters, read the tree and interrogate it directly:
JsonNode user = objectMapper.readTree(raw);
if (!user.has("bio")) {
// absent: the key is not in the object at all
} else if (user.get("bio").isNull()) {
// present, explicit null
} else {
// present and non-null — possibly the empty string
}
Go: zero values
Go flattens by design. encoding/json unmarshals a missing property and an explicit null into the same zero value of the field's type: the empty string, zero, false, or nil. A plain string field cannot tell you which of the three it saw. Pointer fields get you halfway — nil means absent or null — but the first two absences remain fused. Separating them requires raw JSON capture:
type User struct {
Bio string `json:"bio"` // absent, null, and "" all land here as ""
}
type UserTagged struct {
Bio *string `json:"bio"` // nil = absent OR null; "" = empty string
}
type UserRaw struct {
Bio json.RawMessage `json:"bio"` // empty = absent; "null" = explicit null
}
The zero-value philosophy is deliberate, but it is a standing reminder: if your contract distinguishes absent from null from empty, Go field types must be chosen with that contract in mind. Retrofitting pointer fields across a large struct after the fact is exactly as fun as it sounds.
SQL: NULL versus the empty string
SQL formalized the null-versus-empty distinction decades ago and still refuses to flatten it. NULL means unknown: NULL = NULL evaluates to unknown, not true; COUNT(column) skips NULL rows but counts rows holding the empty string. Any ORM that maps a missing JSON key to a NULL column — or a JSON null to an empty string because the column is NOT NULL — has performed a translation the sender never authorized. Check what your persistence layer actually writes; the JSON you received and the row you stored may disagree about which absence occurred.
Where the Collapse Bites
PATCH semantics
The clearest real-world stake is partial update semantics. RFC 7396, JSON Merge Patch, is precise: a null member in the patch means set this member to null — in practice, clear it — while an absent member means leave it untouched. The empty string means just that. The format is elegant precisely because it spends all three absences on three different meanings:
PATCH /users/usr_84c1
Content-Type: application/merge-patch+json
{
"bio": null,
"nickname": "ace"
}
The server reads this as: clear the bio, set the nickname to ace, and leave every field not mentioned exactly as it is. The classic accident follows directly. A client that renders a full edit form, keeps untouched fields as null, and serializes the whole object as the patch body will wipe every field the user did not open:
{
"displayName": null,
"bio": "hello"
}
The user only meant to update the bio; displayName was never touched, but the form initialized it to null and the serializer shipped it. Servers can defend by ignoring nulls, but that only moves the problem: a user who genuinely wants to clear a field no longer can. The durable fix is a client that distinguishes untouched (omit the key) from cleared (send null) — form state must carry three states per field, not two. RFC 6902 JSON Patch sidesteps the overload by making each operation explicit, at the cost of a more verbose body.
Interfaces that print the word null
The second failure is cosmetic but reputation-defining: an interface that shows the user the literal word null — or undefined, or None — because an absence value was stringified. A JavaScript template literal prints null inline; a Python f-string prints None; Java's String.valueOf turns a null reference into four characters of text. A profile card reading Welcome back, null is not a rendering bug in any technical sense — the absence was faithfully converted and faithfully displayed. The bug is upstream: a display layer must decide what each absence means for humans — hide the fragment, show a placeholder, show a dash — and that requires knowing which absence it received.
Defaulting mistakes
The third failure lives in client fallback logic. The pattern const limit = payload.limit || 100 is wrong twice: an explicit null becomes 100 — the caller said no limit is known, the client heard use the default — and a legitimate zero becomes 100, because the client overruled it. Python's payload.get("limit", 100) fails identically. A default is a statement about missing information, so it should fire only for genuinely absent information — never for an explicit null or an explicit zero, which are both information. Numeric defaults deserve extra care when the value is an identifier: substituting zero for a missing ID can cascade into lookups against record zero, and identifiers crossing language boundaries must survive as exact integers — see Safe Integers and the 2^53 Boundary.
Absence is data. When a field can legitimately be unknown, deliberately empty, or not applicable, a single sentinel cannot encode all three states. Decide per field which absences are legal, and make the client's handling of each one explicit — or the runtime will decide for you, in production.
Determining What You Actually Received
When a payload misbehaves, the first diagnostic question is always the same: which of the three absences did I actually receive? Answer structurally, not visually — a formatted view can make null look like an empty string, and a missing key looks like nothing at all. Ask in order: does the key exist — a hasOwnProperty check, a has() call, a sentinel get(); if it exists, is the value null; if it is a string or container, is it empty. Three boolean answers, eight possible field states, each implying different handling.
Test it yourself: Paste {"bio": null} into the JSON Inspector and expand the object: the key is present and its value is null. Delete value and key together and you are left with {}, where the key is simply gone. Then load both documents into JSON Compare: the structural diff reports the property as removed, not changed-to-null — exactly the distinction a merge-patch server acts on.
| Representation | Most likely meaning | Safe client handling |
|---|---|---|
"field": null | Unknown, unset, or unavailable | Treat as no value yet; never substitute a default silently; in a merge patch, means clear this field |
"field": "" | Deliberately cleared; known to be nothing | Treat as a real value; render blank; do not fall back to a placeholder or default |
"field": [] or {} | Computed, and known to contain nothing | Render the empty list or panel; do not hide the section |
| field absent | Not applicable, optional, or — in a patch — do not change | Apply the schema default if one exists; in a merge patch, leave the stored value untouched |
| field absent though required | Contract violation | Reject the payload; respond with a precise error body — see Problem Details errors |
The table is a starting point, not a law: the most-likely-meaning column is the part only your API design can settle. What it does settle is the habit of writing one branch — is the value truthy — for five situations. Five situations, five handlers; anything less is a coin flip someone else's data will eventually call.
Designing a Convention for Your API
None of this works without a written convention, because the JSON format alone cannot carry the meaning. A usable convention answers four questions per field, in writing. First: which absences are legal? Many teams ban the empty string for scalars entirely — a name is either present and non-empty, or null. Second: for collections, does absent mean not-computed and empty mean computed-and-empty, or the reverse? Third: for updates, does absent mean no-change and null mean clear — the merge-patch convention — or are operations explicit? Fourth: what does the client render for each state?
- Prefer banning the empty string for scalar fields where it carries no distinct meaning; every legal empty string is a state every client handles forever.
- Keep the container rule symmetric across every endpoint; one endpoint returning absent-for-empty and another returning an empty array will poison exactly the generic client code you share between them.
- Encode nullability and optionality separately in OpenAPI —
nullablefor values, the required list for keys — and generate client types from the schema so the distinction survives code generation. - Reject, do not guess. A payload that uses an absence your contract forbids should fail validation with a precise error, not be coerced into whatever the deserializer felt like.
Enforce the convention where the payload crosses the boundary: server-side validation before persistence, client-side normalization before state, and contract tests that send all three absences to every endpoint that allows them. The cost is a few lines per field at design time; the alternative is a PATCH that deletes data or a dashboard that renders null — discovered weeks later, from a support ticket.
OpenAPI separates nullable from optional for a reason: nullability constrains values, optionality constrains keys. A schema that marks a field nullable but required is saying the key must be present and its value may be null — one absence legal, one forbidden. Write the flags per field, not per codebase.
Three absences, three meanings, three handlers. The discipline costs almost nothing when designed in and is disproportionately expensive to retrofit — the signature of a decision worth making early. The next time a field arrives looking empty, resist the reflex to ask whether it is falsy. Ask instead: is it present, is it null, is it empty — and let the answers, not the runtime's convenience operators, decide what your code does next.
Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.