Skip to content

JSON Schema Validator - Draft 2020-12 and Draft-07

JSON Schema
JSON Document

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

Frequently Asked Questions

Which drafts are supported?
2020-12, 2019-09, draft-07 and draft-06. With Draft set to Auto, the validator reads `$schema` and picks the matching Ajv build. A schema with no `$schema` is treated as 2020-12. Draft-04 isn't supported because Ajv 8 dropped it; changing the `$schema` line to draft-07 usually works, apart from boolean `exclusiveMinimum` and `id`.
Are formats like email and date-time checked?
Yes. ajv-formats is loaded, so `date-time`, `date`, `time`, `email`, `uri`, `uuid`, `ipv4`, `ipv6`, `hostname` and the other standard formats are asserted, not just annotated. An unknown format name is ignored instead of failing the whole schema.
What does an error's path mean?
It's a JSON Pointer to the value that failed: `/users/1/email` is the `email` property of the second item in `users`. A missing required property is reported on the object that should contain it, so the path points at the parent and the message names the missing key.
Why does one mistake produce several errors?
The validator runs with allErrors, so it reports everything at once instead of stopping at the first failure. With `anyOf` or `oneOf`, it also reports why each branch failed, followed by a summary saying no branch matched. Fix the error that refers to the branch you meant.
Can my schema use $ref to another URL?
References inside the same schema (`#/$defs/User`) work. Remote references aren't fetched, so a `$ref` to another URL fails with a 'can't resolve reference' error. Paste the referenced schema into `$defs` and point at it there.
Is my data sent anywhere?
No. Ajv runs in your browser and is only downloaded when you paste a schema. Nothing you paste is uploaded.