JSON and data guides

JSON Schema: required, null and extra properties

Write a small object schema and distinguish missing fields, nullable fields and additional properties.

Nav Tools ·

Required checks existence

Listing a property in properties describes how it is validated when present; it does not make the property mandatory. Use required for presence.

A field whose value is null is present. Whether null is accepted depends on that field’s type rule, independently of required.

{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}
{} → invalid
{"name":null} → invalid
{"name":"Ada"} → valid

Model nullable fields deliberately

A union such as ["string","null"] accepts either type. Do not confuse a nullable field with an optional field that can be omitted.

An empty string is still a string. Add minLength when the application requires a nonempty value, and check whitespace rules separately.

{"type":["string","null"]}

Control extra fields

Additional properties are allowed by default. Set additionalProperties to false when unknown fields should be rejected in a simple object schema.

Composed schemas need care: additionalProperties considers the properties declared in its own schema context. Check the selected draft and composition rules.

Validate against real requirements

Generating a schema from one example cannot discover every optional field, enum value or numeric boundary. Treat generation as a starting point.

Add failing fixtures for missing required fields, nulls, wrong types and unexpected keys. Nav Tools validation does not retrieve remote schema references.

References

← JSON and data guides