Skip to content

JSON Schema Validator

This JSON Schema validator checks your data against a schema and lists every rule it breaks, with the path, so you can fix them in one pass.

JSON data
JSON Schema
✕

5 problems

Draft 2020-12

  • $.idtypeInstance type "string" is invalid. Expected "integer".
  • $.ageminimum-3 is less than 0.
  • $.planenumInstance does not match any of ["free","pro","team"].
  • $.seatsmaximum80 is greater than 50.
  • $additionalPropertiesProperty "nickname" does not match additional properties schema.
Valid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to validate JSON against a schema

  1. Paste the data into JSON data and the schema into JSON Schema.
  2. Leave Draft on From $schema, or pick one.
  3. 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.

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.

Questions

Which draft should I write my schema in?

Use 2020-12 unless something you depend on needs an older draft. It is the newest draft this validator supports and the one it uses when $schema is missing.

Why does invalid data still pass?

Check three things. Keywords must be spelled right, because unknown keywords are ignored. Fields you need must be listed in required, because properties alone are optional. And extra fields only fail when the object has "additionalProperties": false.

Can I validate YAML against a JSON Schema?

Convert it first with YAML to JSON, then paste the result into JSON data.

Related tools

Esc