Skip to content
HandyKit

JSON Schema Validator

Check a JSON document against a JSON Schema. Every problem is listed with where it is, what is wrong and which rule failed, as you type.

Runs in your browser. Your input is never uploaded or stored.

These are examples, with deliberate mistakes. Paste your own schema and JSON.

Result

Not valid: 4 problems.

Not valid: 4 problems

Checked against draft 2020-12.

WhereProblemRule
$.id0 is less than 1.minimum
$.roles[1]Instance does not match any of ["admin","editor","viewer"].enum
$Property "nickname" does not match additional properties schema.additionalProperties
$.nicknameThis property isn’t allowed by the schema.false

What JSON Schema is

JSON Schema is a way of describing what a JSON document should look like. You write the rules as JSON, then check documents against them. It is useful for catching missing fields, wrong types and out-of-range values before they cause trouble elsewhere.

Here is a small schema:

{
  "type": "object",
  "required": ["name"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "age": { "type": "integer", "minimum": 0 }
  },
  "additionalProperties": false
}

It allows an object with a non-empty string name and, optionally, a whole-number age of 0 or more. Any other key is rejected.

How to use the tool

  1. Paste your schema into the JSON Schema editor. The tool opens with an example schema, and pasting replaces it.
  2. Paste the document you want to check into JSON to validate. The example document contains deliberate mistakes, and pasting replaces it too.
  3. Leave Schema version on its default, or choose a draft yourself.
  4. Read the result below the editors. It updates as you type.

Validation runs in your browser. Nothing is uploaded.

Reading the results

The result reads Valid or Not valid: N problems. When there are problems, a table lists every one of them, not just the first. It has three columns:

  • Where is the JSONPath of the failing value, such as $.roles[1].
  • Problem is the message, such as String is too short (0 < 1).
  • Rule is the schema keyword that failed, such as minimum, type, enum or required.

If either editor contains a JSON syntax error, the tool shows it with a line and column. Fix those first, because a document that cannot be parsed cannot be checked against a schema.

The tool uses the open-source @cfworker/json-schema library. It interprets schemas rather than compiling them to JavaScript, so it works under a strict Content-Security-Policy. Format keywords such as email, date-time and uri are checked. A $ref works within the same schema, for example #/$defs/address. References to other files or URLs are not fetched.

Choosing a draft

By default the tool reads the $schema keyword. It treats draft-04 as Draft 4, draft-06 and draft-07 as Draft 7, and 2019-09 as Draft 2019-09. Anything else, including a missing $schema, becomes Draft 2020-12. You can override this with the Schema version select, which offers Draft 2020-12, Draft 2019-09, Draft 7 and Draft 4.

Two changes matter most in practice:

  • Drafts 2019-09 and 2020-12 use $defs for reusable pieces. Earlier drafts use definitions.
  • Draft 2020-12 uses prefixItems for tuple-style arrays. Earlier drafts used an array form of items.

Common mistakes

  • Forgetting additionalProperties: false. Without it, any extra keys are allowed.
  • Putting required in the wrong place. It belongs at the object level, as an array of names, not inside an individual property.
  • Expecting integer to reject 1.0. Most validators reject 1.5 but accept 1.0, because the value is mathematically a whole number.

Validating in code

Once a schema behaves as you want, you can use it in your own project. With Ajv in JavaScript:

import Ajv from 'ajv/dist/2020';

const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);

validate(data) || console.log(validate.errors);

The allErrors option reports every problem rather than stopping at the first. Ajv does not check formats on its own, so add the ajv-formats package if you want email and similar keywords enforced.

In Python, use the jsonschema package:

from jsonschema import validate

validate(instance=data, schema=schema)

This raises a ValidationError if the data does not match the schema.

Frequently asked questions

Which JSON Schema drafts are supported?

Draft 2020-12, Draft 2019-09, Draft 7 and Draft 4. In the default mode the tool reads your "$schema" keyword and falls back to Draft 2020-12 if it is missing. You can pick a draft yourself with the Schema version select.

Does it check formats such as email and date-time?

Yes. Format keywords such as email, date-time and uri are checked, so a value that does not match its format is reported as a problem in the results table.

Can it load a $ref from a URL or another file?

No. A $ref works within the same schema, for example #/$defs/address, but references to other files or URLs are not fetched. If your schema depends on external pieces, copy them into the schema’s $defs first.

Is my data uploaded anywhere?

No. Validation runs in your browser, so your schema and your document stay on your device.

Are all errors listed, or only the first?

All of them. The result says how many problems were found, and the table lists each one with its location, message and the schema keyword that failed.

How is this different from checking JSON syntax?

Syntax checking confirms that the text is well-formed JSON, with matching brackets, quoted keys and so on. Schema validation checks that well-formed JSON has the right content, such as required fields and correct types. This tool reports syntax errors too, but for a plain syntax check the JSON Validator is simpler.

Guides

  • · 3 min read

    JSON Schema Explained, with Examples

    What JSON Schema is, the keywords you will use most, and how to read validation errors, with a worked example schema, a valid document and an invalid one.