JSON Schema Validator - Draft 2020-12 and Draft-07
Check a document against a schema
Paste a JSON Schema on the left and a JSON document on the right. The result updates as you type. Validation is
done by Ajv, the validator behind a large share of
JavaScript tooling, with ajv-formats added and every error collected. Each error shows the JSON Pointer of the
failing value, the line it's on in your document, and a sentence that says what's wrong, such as
Expected integer, got string. instead of Ajv's raw must be integer.
This checks data against a schema. To check whether a file is valid JSON at all, use the JSON validator.
Example
Schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"email": { "type": "string", "format": "email" },
"role": { "enum": ["admin", "editor", "viewer"] }
},
"required": ["id", "email"],
"additionalProperties": false
} Document:
{
"id": "42",
"email": "grace@",
"role": "owner",
"team": "infra"
} Result, 4 errors (draft 2020-12):
(root) line 1 Property "team" is not allowed by the schema.
/id line 2 Expected integer, got string.
/email line 3 Not a valid email string: "grace@".
/role line 4 Must be one of "admin", "editor", "viewer". "42" fails because JSON Schema doesn't coerce types: a string of digits isn't an integer. The extra
team key is reported on the root object, since that's where
additionalProperties: false lives.
Picking the draft
Leave Draft on Auto unless you have a reason not to. Auto reads the $schema URI:
http://json-schema.org/draft-07/schema# (or draft-06) runs on Ajv's draft-07 build,
https://json-schema.org/draft/2019-09/schema on the 2019-09 build, and anything else on 2020-12.
The drafts differ in ways that change results. In draft-07, items given as an array checks tuple
positions. In 2020-12 that job moved to prefixItems, and items always applies to every
element. A tuple schema written for draft-07 and run as 2020-12 fails to compile here, which is better than
quietly checking the wrong thing.
The schema itself is checked against its draft's meta-schema before any data is validated. A typo like
"type": "intger" shows up as a compile error naming the bad value, not as a document that
mysteriously passes.
Common surprises
additionalProperties: false only sees properties declared in the same schema object. If you combine
schemas with allOf, properties from the other branches count as extra and get rejected. Draft
2019-09 added unevaluatedProperties: false for that case, and this validator supports it.
required doesn't reject null. { "email": null } has the key, so it passes
required and fails type instead, unless the type is
["string", "null"].
Large integers are compared as JavaScript numbers, so a value like 9007199254740993 is rounded
before checks such as maximum or const run. Type checks are unaffected.
No schema yet?
Generate one from a sample with JSON to JSON Schema, then paste it here and tighten it until bad documents fail. If the data is going into TypeScript, the same sample also works with JSON to Zod and JSON to TypeScript.
Related Tools
JSON to YAML Converter
Convert JSON data to clean, readable YAML format instantly.
JSON to XML Converter
Transform JSON objects and arrays into well-formed XML documents.
JSON to CSV Converter
Flatten JSON arrays into downloadable CSV spreadsheets in one click.
YAML to JSON Converter
Convert YAML configuration files to JSON format instantly.