How to validate JSON against a schema
- Paste the data into JSON data and the schema into JSON Schema.
- Leave Draft on From $schema, or pick one.
- Results update as you type; Validate or Ctrl + Enter runs the check again.
The schema is saved apart from the data, so it is still there for the next document.
Example
A product listing schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["sku", "price", "tags", "stock"],
"properties": {
"sku": { "type": "string", "pattern": "^[A-Z]{3}-[0-9]{3}$" },
"price": { "type": "number", "exclusiveMinimum": 0 },
"tags": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
"stock": { "type": "integer", "minimum": 0 },
"updated": { "type": "string", "format": "date-time" }
}
}
Data that breaks it five ways:
{
"sku": "lmp-200",
"price": 0,
"tags": ["desk", "lamp", "desk"],
"updated": "yesterday"
}
Result:
5 problems · Draft 2020-12
$ required Instance does not have required property "stock".
$.sku pattern String does not match pattern.
$.price exclusiveMinimum 0 is less than 0.
$.tags uniqueItems Duplicate items at indexes 0 and 2.
$.updated format String does not match format "date-time".
Each line gives the path in the data ($ is the root), the failed keyword and the reason. Validation does not stop at the first failure.
How the JSON Schema validator picks a draft
From $schema recognizes 2020-12, 2019-09, draft-07 and draft-04 in the $schema URL. Anything else, including draft-06 or no $schema at all, is checked as 2020-12. The draft changes some keywords: in draft 4, exclusiveMinimum is a true or false modifier of minimum; in draft 7 and later it is a number.
Formats and references
format is enforced: values that don’t fit date-time, date, uri, uuid, ipv4 or hostname fail. The email check is loose, and lin@example passes.
$ref works within the schema, for example to #/$defs/address. Other files and URLs are not fetched (“Unresolved $ref”), so copy those definitions into $defs.
The schema is not checked against the meta-schema: a wrong type name such as "strin" fails every value instead of being reported as a schema mistake.
Related tools
Start from a sample with the JSON schema generator. For a syntax error in either pane, the status bar names the side, the JSON validator gives the line and a fix, and common JSON errors explains parser messages. For types, try JSON to TypeScript.