JSON Schema
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$vocabulary": {}, "$id": "...", "title": "...", "description": "...", "properties": { "value": { "type": "number" }, "enabled": { "type": "boolean" }, "text": { "type": "string" }, "nothing": { "type": "null" }, "zero": { "const": 0 }, "category": { "enum": ["stable", "unstable", "draft", "dev"] }, "tags": { "type": "array" }, "nested": { "type": "object", "properties": { "first": { "type": "string" }, "last": { "type": "string" } } } }, "required": ["value", "enabled"]} JSON
{ "value": 115, "enabled": true, "text": "hello world", "nothing": null, "zero": 0, "category": "stable", "tags": ["cool", "awesome", "fantastic"], "nested": { "first": "Gordon", "last": "Freeman" }} YAML
# $schema: ./schema.jsonvalue: 115enabled: truetext: hello worldtags: [cool, awesome, fantastic]nothing: nullzero: 0category: stablenested: first: Gordon last: FreemanVersions
| Draft 2020-12 | https://json-schema.org/draft/2020-12/schema |
| Draft 2019-09 | https://json-schema.org/draft/2019-09/schema |
Legacy Drafts
| Draft 7 | https://json-schema.org/draft/draft-07/schema |
| Draft 6 | https://json-schema.org/draft/draft-06/schema |
| Draft 4 | https://json-schema.org/draft/draft-04/schema |
| Draft 3 | https://json-schema.org/draft/draft-03/schema |
| Draft 2 | https://json-schema.org/draft/draft-02/schema |
| Draft 1 | https://json-schema.org/draft/draft-01/schema |
| Draft 0 | https://json-schema.org/draft/draft-00/schema |
Types
Const
{}Enum
{ "enum": ["pink", "blurple", false, null, ...] Value must be one of the specified options
JSON Schema Docs — enum
}Null
Boolean
Number
{ "minimum": 0, "maximum": 100, "exclusiveMinimum": 0, "exclusiveMaximum": 100, Range constraints can be defined
minimum ≥ value ≥ maximum
exclusiveMinimum value exclusiveMaximum
}String
{ "minLength": 1, "pattern": "^[a-z]+$" Regex constraint can be defined
JSON Schema Docs — string regex
Regular Expressions
}Array
{ "minItems": 1, "items": { "type": "number", ... }, Type constraint can be defined for the array items
JSON Schema Docs — array items
11 collapsed lines
"contains": { "type": "number", ... }, "minContains": 1, "maxContains": 3, Alternatively, Type constraints can be defined for a certain amount of items
JSON Schema Docs — array contains
"prefixItems": [ { "type": "string", ... }, { "type": "number", ... }, { "type": "boolean", ... }, ... ], "items": false, Alternatively, Type constraints can be defined for each of the items
Setting items to true only applies the schema for the first items and allows additional items
JSON Schema Docs — array tuple validation¶
"unevaluatedItems": false Additional items constraint outside of items, contains and prefixItems can be defined
JSON Schema Docs — array unevaluated items
}Object
{ "minProperties": 1, "maxProperties": 10,
"properties": { "id": { "type": "string", ... }, "enabled": { "type": "boolean", ... }, "value": { "type": "number", ... } }, "required": ["id", "enabled", ...],
13 collapsed lines
"patternProperties": { "^S_": { "type": "string", ... }, "^N_": { "type": "number", ... } },
"propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
"additionalProperties": false, "additionalProperties": { "type": "string", ... },
"unevaluatedProperties": false, }Features
Annotations
{ "$comment": "...",
"title": "...", "description": "...", "default": null, "examples": ["zombie", 115, ...], "deprecated": true, "readOnly": true, "writeOnly": false} String Annotations
{ "type": "string", "contentEncoding": "base64", "contentMediaType": "image/png"}{ "type": "string", "contentMediaType": "application/json", "contentEncoding": "base64", "contentSchema": ""}Conditional Schema
{ "dependentRequired": { "category": ["subcategory"] },
"dependentSchemas": { "required": ["category"], "properties": { "subcategory": { "minItems": 1 } } },
"if": { "properties": { "enabled": { "const": true } } }, "then": { "properties": { "text": { "minLength": 15 } } }, "else": { "properties": { "text": { "minLength": 1 } } }, }Boolean Schema composition
{ "allOf": [], "anyOf": [], "oneOf": [], "not": {}}Modular Schema composition
{ "$id": "", "$anchor": "", "$ref": "#/$defs/diskDevice", "$defs": "",
"$dynamicAnchor": {}, "$dynamicRef": {}}