Skip to content

FIELD NOTES / A DECISION GUIDE

Null, Empty String, or Missing: An API Field Contract Worksheet

On this page
AI-generated illustration; not taken on location · Conceptual comparison of a null field, an empty string field, and a missing field.
AI-generated illustration; not taken on location · These three payloads represent distinct states; their application meaning depends on the endpoint’s contract.AI-generated illustration

Review {"name":null}, {"name":""}, and {} as three separate inputs. Establish whether the property is supplied, identify its value when present, and apply the requirements for the specific operation. Choose any fallback only after deciding which distinctions the application needs to retain.

This guide is a contract-review worksheet with a completed hypothetical example. It specifies expected application outcomes without presenting undocumented JavaScript operator behavior as implementation guidance. The example’s rules are deliberately stated in full so you can see how requirements become reviewable decisions.

Use FormatBits JSON formatting to inspect the payloads, then evaluate field requirements separately. Successful JSON parsing does not establish that required properties are present. Formatting supports inspection; the endpoint’s contract and your application checks determine what an input means and whether it is acceptable.

Three payloads, three states

Begin with three small payloads that keep the field decision visible:

{"name": null}
{"name": ""}
{}

The first supplies name with a null value. The second supplies name with a zero-length string. The third omits name. Keep those observations separate from decisions such as accepting a request, clearing a stored value, or displaying a replacement label.

Give the example an explicit contract

For the rest of this worksheet, imagine a hypothetical application reviewing a profile update. Its existing stored name is "Mira". Define the following requirements solely for this example:

  • An omitted name leaves the stored name unchanged.
  • An explicit null clears the stored name.
  • An empty string is rejected.
  • false and 0 are rejected for this field.
  • Text containing only spaces is rejected.
  • The ordinary nonempty string "Ada" is accepted and replaces the stored name.
  • A rejected update leaves the stored name unchanged.
  • A cleared name is displayed as "Unnamed"; an existing name is displayed as stored.

These are invented requirements for a worked exercise, not claims about a real API. They provide enough information to complete the review without borrowing an update convention from another service.

Each case starts independently with "Mira" stored. The cases are not a sequence of updates. This matters because a missing-field test should demonstrate its own omission rule, rather than inherit the result of an earlier clearing test.

The central question is now concrete: can the proposed implementation preserve the distinction between leaving "Mira" unchanged, clearing it, and rejecting the request?

Check whether the property exists

Make presence the first decision in the review. For the hypothetical update, the application must establish whether the incoming payload supplies its own name property before applying the rules for a supplied value.

The expected outcomes are straightforward: both {"name":null} and {"name":""} supply the property; {} does not. Those expectations describe the input examples and the requirement the implementation must meet.

Write a checkable requirement

A useful review statement is: “Determine whether the request supplies its own name property. If it does not, preserve the current stored name and finish processing this field.” This connects the presence decision directly to the required result.

For {}, the completed example therefore accepts the update and retains "Mira". It does not apply the clearing rule or the empty-string rejection rule, because those rules concern supplied values.

For {"name":null}, the review proceeds to the value decision. Recognizing the property as present does not establish acceptance by itself; it establishes which part of the contract applies next.

Keep the implementation question precise

If the implementation proposes Object.hasOwn(payload, "name"), ask the reviewer to establish that the chosen mechanism meets the own-property requirement in the application’s supported environment. This worksheet does not supply a JavaScript reference or claim verified execution results for that expression.

Similarly, when code reads payload.name, identify where it separately establishes the presence information required by the contract. A value variable alone is not a review record of how that requirement was satisfied.

Keep this review focused on an observable result: the missing-field case must reach the preserve-current-name decision, while the two supplied-field cases must reach value review.

Check the value explicitly

After establishing presence, review the supplied value against an explicit acceptance rule. In the hypothetical contract, null is accepted as a request to clear the stored name. An empty string is rejected. These outcomes differ even though neither request supplies an ordinary display name.

A language-neutral decision sketch makes the required order reviewable:

If name is absent:
    Accept; preserve the stored name.
Otherwise, if name is explicit null:
    Accept; clear the stored name.
Otherwise, if name is an empty string:
    Reject; preserve the stored name.
Otherwise, if name is false, 0, or text containing only spaces:
    Reject; preserve the stored name.
Otherwise, if name is the example string "Ada":
    Accept; store "Ada".
Otherwise:
    Consult the field's additional acceptance requirements.

This sketch specifies the exercise’s outcomes. It is not executable code or a complete validator for every possible input.

Do not hide several decisions behind “empty”

For this example, rejection of "", false, 0, and " " is an explicit requirement. It does not follow merely from assigning those inputs a shared label.

Whitespace deserves its own stated rule. Here, text containing only spaces is rejected and the previous name remains unchanged. The example does not introduce automatic trimming or define acceptance for every other form of text. For a real endpoint, ask whether text should be preserved, transformed, or rejected and obtain a rule covering the inputs you intend to support.

The proposed JavaScript comparisons payload.name === null and payload.name === "" belong in implementation review once their behavior has supporting language documentation. The contract decisions above remain useful independently: they give the implementation reviewer specific branches and expected application outcomes to verify.

Choose defaults without losing distinctions

Decide what the fallback is for before selecting an expression. In the hypothetical application, "Unnamed" is a display label for a cleared stored name. It is not a replacement value that makes an otherwise rejected request acceptable.

That distinction produces concrete results. An omitted field retains "Mira" and displays "Mira". Explicit null clears the stored name and displays "Unnamed". An empty-string request is rejected, so the existing name and its display remain "Mira".

Specify the policy independently of syntax

Consider three possible fallback policies during review:

  • Use a replacement only when the property is omitted.
  • Use a replacement for omission and explicit null.
  • Apply the example’s update rules first, then derive a display label from the accepted stored state.

The worked example chooses the third policy. The first two would require separate justification before being used to process its update requests.

Candidate JavaScript expressions may include payload.name || "fallback", payload.name ?? "fallback", or a presence-based conditional. This worksheet does not assert an operator result table without supplied language documentation. Instead, compare any candidate implementation with the completed outcomes in the final section.

Preserve rejected inputs as rejected inputs

Include false and 0 when reviewing a proposed default. Under this example’s requirements, both must produce rejection and preserve "Mira". An implementation that silently substitutes a label and accepts either request would fail the stated contract, regardless of how convenient its display output looks.

Also check the empty-string case explicitly. A fallback that turns the rejected request into an accepted update changes the requirements. Keep request acceptance, stored state, and displayed text separately observable so a plausible label cannot conceal the wrong update decision.

Read the endpoint’s contract

For a real integration, replace the hypothetical rules with requirements for the specific endpoint and operation. Resolve property requirements, accepted values, and update actions separately. A statement about whether a property must be supplied does not answer every question about the values the operation accepts.

Start with the request you are actually constructing. Is name required? Is explicit null accepted? Is an empty string accepted? What additional restrictions apply to text? Then determine the documented action for each accepted input.

Keep request and response questions separate

When consulting an example, identify whether it shows a request or a response and which operation it describes. Ask whether the documentation explicitly supports the behavior you need to implement.

A response example containing "name": null leaves an important implementation question unanswered unless its surrounding contract addresses it: what should this update request do when the caller supplies null? Record the request rule directly instead of deriving it from the appearance of a response.

No real endpoint examples are supplied for this article. The clearing and preservation behavior in the worked exercise belongs only to its stated hypothetical requirements.

Turn ambiguity into a specific question

For updates, ask the API owner to resolve the exact payloads: “For this operation, what happens with {}, {"name":null}, and {"name":""}?” Ask separately whether an unacceptable value rejects the update or leads to another documented action.

If the answer covers only omission, retain the null and empty-string questions as unresolved. Do not fill those gaps with the exercise’s rules. Once resolved, replace the relevant expected outcomes in your own decision matrix and review the implementation against that contract.

Inspect the payload and test the decision

Use FormatBits JSON formatting to inspect each example individually. Locate name where it appears and check the visible value. Then move to the separate presence, acceptance, and application decisions.

Successful JSON parsing does not establish that required properties are present. A formatted payload is therefore an inspection aid; schema checks or application logic must address the field requirements relevant to your endpoint.

Use one completed decision matrix

The following matrix consolidates the hypothetical example. Every row starts with "Mira" stored, and its outcomes follow the requirements stated earlier.

Input Presence Expected decision Stored name afterward Display afterward
{} Absent Accept; preserve "Mira" Mira
{"name":null} Present Accept; clear Cleared Unnamed
{"name":""} Present Reject "Mira" Mira
{"name":false} Present Reject "Mira" Mira
{"name":0} Present Reject "Mira" Mira
{"name":" "} Present Reject "Mira" Mira
{"name":"Ada"} Present Accept; replace "Ada" Ada

Run the implementation against each case and compare all relevant outputs. Checking displayed text alone is insufficient for this exercise: several rejected requests display the same existing name as an accepted omission.

Diagnose a mismatch by its consequence

If {} clears the stored name, investigate the presence decision and omission handling. If the empty string produces an accepted update, investigate value acceptance and any fallback applied before that decision. If null clears the name correctly but the interface fails to show "Unnamed", investigate the display policy separately.

For your own endpoint, keep this single matrix structure and replace the hypothetical expectations with documented requirements. Add cases only when they exercise another relevant rule. Leave an unresolved expectation visibly unanswered rather than treating the current implementation’s output as the specification.

The practical deliverable is a reviewable connection between an input, its contract requirement, and its expected outcome. JSON inspection helps you see the input; the completed decisions establish what the application must do with it.