Cryonel

JSON Schema Keywords Reference

JSON Schema describes allowed JSON instances with validation and annotation keywords. Declare the schema dialect and test with the same validator used by the application because draft support varies.

Core type and value keywords

KeywordPurpose
typeRestricts the JSON type or allowed types.
enumAllows values equal to one of a fixed set.
constRequires equality to one value.
titleProvides a short human-readable schema title.
descriptionExplains intended meaning and usage.
defaultAnnotates a default value; validators do not necessarily insert it.
examplesProvides illustrative values that should satisfy the schema.

Object keywords

properties maps known property names to schemas, but it does not make them mandatory. required is an array of names that must appear. additionalProperties controls names not covered by the applicable property rules and can be false or a schema for dictionary values. patternProperties applies schemas to names matching regular expressions. Property names themselves can be constrained with propertyNames.

Array keywords

items describes array elements under the selected dialect. prefixItems in newer dialects describes positional tuple entries. minItems and maxItems bound length, while uniqueItems: true requires pairwise-unique values under JSON equality. contains requires matching elements and can work with minimum and maximum contains counts where supported.

String constraints

minLength and maxLength constrain string length according to the dialect's character model. pattern applies a regular expression without automatically anchoring the whole string. Add anchors when full-value matching is intended. format can annotate values such as date-time, email, URI, or UUID, but enforcement and format vocabularies vary by validator.

Numeric constraints

minimum and maximum are inclusive bounds. exclusiveMinimum and exclusiveMaximum express strict bounds under the dialect syntax. multipleOf constrains values to a numeric step. Consider consumer precision when schemas permit large integers or decimals; JSON's number syntax does not guarantee one machine representation.

Composition and conditionals

KeywordValidation rule
allOfEvery listed subschema must match.
anyOfAt least one listed subschema must match.
oneOfExactly one listed subschema must match.
notThe listed schema must not match.
if / then / elseApplies conditional validation under supported dialects.

Keep oneOf branches distinct so valid data cannot match several. Use composition to express real domain rules, not merely to satisfy a generator. Review error output for every branch because a top-level composition failure can hide the actionable constraint.

Identifiers and references

$schema declares the dialect. $id establishes a schema identifier and can affect reference resolution. $ref points to another schema or fragment using URI-reference and JSON Pointer rules. Relative references resolve from their current base, so bundled and multi-file schemas need portable paths and case-sensitive CI validation.

Frequently Asked Questions

Does properties imply required?

No. List mandatory names in required.

What does additionalProperties false do?

It rejects otherwise unpermitted object names.

How do oneOf and anyOf differ?

oneOf requires exactly one match; anyOf allows one or more.

Related Tools and Guides