JSON Schema

schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",

$schema specifies the version of the JSON Schema standard

JSON Schema Docs$schema

"$vocabulary": {},
"$id": "...",
"title": "...",
"description": "...",
"type": "object",

type can be one of:

"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

data.json
{
"value": 115,
"enabled": true,
"text": "hello world",
"nothing": null,
"zero": 0,
"category": "stable",
"tags": ["cool", "awesome", "fantastic"],
"nested": {
"first": "Gordon",
"last": "Freeman"
}
}

YAML

data.yml
# $schema: ./schema.json
value: 115
enabled: true
text: hello world
tags: [cool, awesome, fantastic]
nothing: null
zero: 0
category: stable
nested:
first: Gordon
last: Freeman

Versions

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

JSON Schema Docs — Drafts

Types

Const

{
"const": "zero"

Value must be it
JSON Schema Docs — const

}

Enum

{
"enum": ["pink", "blurple", false, null, ...]

Value must be one of the specified options
JSON Schema Docs — enum

}

Null

{ "type": "null" }

Value must be null
JSON Schema Docs — null

Boolean

{ "type": "boolean" }

Value of true or false
JSON Schema Docs — boolean

Number

{
"type": "number",

type can be number or integer
JSON Schema Docs — numeric

"minimum": 0,
"maximum": 100,
"exclusiveMinimum": 0,
"exclusiveMaximum": 100,

Range constraints can be defined

  • minimum ≥ value ≥ maximum
  • exclusiveMinimum value exclusiveMaximum

JSON Schema Docs — numeric range

"multipleOf" : 10,

Multiple constraint can be defined
JSON Schema Docs — numeric multiples

}

String

{
"type": "string",

Value of text "..."
JSON Schema Docs — string

"minLength": 1,
"maxLength": 10,

Length constraints can be defined
JSON Schema Docs — string length

"pattern": "^[a-z]+$"
}

Array

{
"type": "array",

Value of a list [...]
JSON Schema Docs — array

"minItems": 1,
"maxItems": 5,

Length constraints can be defined
JSON Schema Docs — array length

"uniqueItems": true,

Uniqueness constraints can be defined
JSON Schema Docs — array uniqueness

"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

{
"type": "object",

Value of an object {...}
JSON Schema Docs — 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": {}
}

Resources

This website is currently available on Desktop only
Let @Stephcraft know on Discord you'd like a Mobile version

Join Discord