Skip to main content

Null and missing values

Golf clubs publish different levels of detail. The API preserves the distinction between confirmed negative values, unknown values and fields that do not apply.

Three different states

Consider this field:

{
"dogs_allowed": false
}

false means the available information explicitly indicates that dogs are not allowed.

{
"dogs_allowed": null
}

null means the value could not be determined reliably.

If dogs_allowed is omitted, the field may not be part of that response projection or API resource. Consult the endpoint schema before assigning meaning to an omitted field.

Do not coerce unknown values

This code loses information:

const dogsAllowed = Boolean(club.dogs_allowed);

Both false and null become false.

Handle each state explicitly:

function accessLabel(value) {
if (value === true) return 'Allowed';
if (value === false) return 'Not allowed';
return 'Unknown';
}

Dependent fields

Some values only make sense when another condition is true:

{
"dogs_allowed": true,
"dogs_leash_required": true
}

When dogs are not allowed, a leash requirement may be null because it does not apply:

{
"dogs_allowed": false,
"dogs_leash_required": null
}

Filtering

A filter such as:

?dogs=true

returns clubs where the value is confirmed as true. It should not include unknown records.

If the interface needs to show every club, do not filter out unknown values silently. Display an appropriate unknown state and allow users to confirm important conditions directly with the club.