JSON Schema Cheat Sheet
The keywords you use most often when writing a JSON Schema, grouped by what they validate.
Any value
| Keyword | Meaning | Example |
|---|---|---|
type | Allowed type(s): string, number, integer, boolean, object, array, null | {"type": "string"} |
enum | Value must be one of a fixed list | {"enum": ["admin", "viewer"]} |
const | Value must equal exactly this | {"const": "v1"} |
Objects
| Keyword | Meaning | Example |
|---|---|---|
properties | Schema for each known key | {"properties": {"id": {"type": "integer"}}} |
required | Keys that must be present | {"required": ["id", "email"]} |
additionalProperties | false rejects keys not listed | {"additionalProperties": false} |
minProperties / maxProperties | Limit the number of keys | {"minProperties": 1} |
Arrays
| Keyword | Meaning | Example |
|---|---|---|
items | Schema for every element | {"items": {"type": "string"}} |
minItems / maxItems | Limit the length | {"minItems": 1} |
uniqueItems | No duplicates | {"uniqueItems": true} |
prefixItems (2020-12) | A different schema per position (tuples) | {"prefixItems": [{"type": "number"}, {"type": "string"}]} |
Strings and numbers
| Keyword | Meaning | Example |
|---|---|---|
minLength / maxLength | String length limits | {"minLength": 1} |
pattern | Regular expression the string must match | {"pattern": "^[a-z]+$"} |
format | email, date-time, uri, uuid and others | {"format": "email"} |
minimum / maximum | Inclusive numeric limits | {"minimum": 0} |
exclusiveMinimum / exclusiveMaximum | Exclusive limits (numbers since draft-06; booleans in draft-04) | {"exclusiveMinimum": 0} |
multipleOf | Must be a multiple of | {"multipleOf": 0.01} |
Combining and reusing
| Keyword | Meaning | Example |
|---|---|---|
allOf | Must match every schema | {"allOf": [{...}, {...}]} |
anyOf | Must match at least one | {"anyOf": [{"type": "string"}, {"type": "null"}]} |
oneOf | Must match exactly one | {"oneOf": [{...}, {...}]} |
not | Must not match | {"not": {"type": "null"}} |
if / then / else (draft-07+) | Conditional rules | {"if": {...}, "then": {...}} |
$defs and $ref | Define a part once and reuse it (older drafts: definitions) | {"$ref": "#/$defs/address"} |
Good to know
- Set $schema (for example https://json-schema.org/draft/2020-12/schema) so tools know which draft you mean.
- format may be treated as an annotation only by some validators; test the formats you rely on.
- A required error points at the object that is missing the key, because the key itself does not exist.
Validate against a schema · All cheat sheets · JSON examples