liveBook · Manning

Missing value

As explained in API Design Patterns

A missing value is a value that is absent because its field is omitted rather than explicitly assigned.

A missing value occurs when a field is omitted rather than explicitly assigned. APIs must distinguish omission from an explicit null, because each can express a different user intention. section 5.1.1

Treat these states as distinct unless the API deliberately defines otherwise:

  • An ordinary value supplies data, such as a fruit color of "red". section 5.1.1
  • An empty string supplies a value, even though that value contains no characters. section 5.1.1
  • An explicit null supplies a non-value and may instruct an update to set the field to null. section 5.1.1 section 8.3.5
  • A missing field supplies no field value; in an inferred field mask, it usually means the field is not being updated. section 8.3.5

Removing a dynamic key

To remove the test key from a ChatRoom settings map, send an explicit field mask while omitting the field from the request body: PATCH /chatRooms/1?fieldMask=settings.test with {} as the body. This removes the key rather than assigning it null. section 8.3.6

fruit1 = { name: "Apple", color: "red" };
fruit2 = { name: "Apple", color: "" };
fruit3 = { name: "Apple", color: null };
fruit4 = { name: "Apple" };

Compare an ordinary value, an empty string, an explicit null, and an omitted color field in otherwise identical Fruit objects. section 5.1.1

Do not use a zero value as a default marker when zero is also meaningful: doing so prevents callers from expressing an intentional zero and makes behavior unpredictable. section 5.3.2 section 5.2

How API Design Patterns covers it

How deep it goes
Explains omission versus null through inferred masks, dynamic-map deletion, and zero-value ambiguity with API examples.
Examples
Uses Fruit color objects, PATCH descriptions, ChatRoom settings deletion, and zero-value Boolean defaults.
What it assumes
Assumes JSON-like objects and API request basics while clarifying omission, null, and zero-value behavior.
What you can do after
Apply it via field masks to distinguish omission, explicit null, and dynamic-key removal in API requests.
How it connects
Connects null value, field mask, partial update, dynamic data structure, and default value.

Also explained in

Compare how 35 books explain missing value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.