# JSON Schema Validator

> Validate JSON data against a JSON Schema (drafts 4, 6, 7, 2019-09 and 2020-12) and see every error with the path into your data and into the schema.

- Page: https://notadevblog.com/en/tools/developer/json-schema-validator/
- German version: https://notadevblog.com/de/tools/developer/json-schema-validator.md
- Category: Developer

## At a glance

- **Processing:** Locally in your browser, also offline once the page has been opened. Input never leaves your device.
- **Drafts:** 4, 6, 7, 2019-09 and 2020-12, read from $schema
- **References:** Local $ref and $id only; remote URLs are never fetched

## For agents

WebMCP: the page registers these functions via document.modelContext in browsers that support it.
ES module: https://notadevblog.com/core/json-schema-validator.js
Every function returns { "ok": true, ... } or { "ok": false, "error": { "code", "message" } }.

### json_schema_validate

Check JSON data against a JSON Schema (drafts 4, 6, 7, 2019-09, 2020-12; draft "auto" reads $schema, default 2020-12). schema and data may be JSON text or already-parsed values; a string for data is always parsed as JSON. Returns valid plus errors with instancePath (JSON Pointer into the data), schemaPath, keyword and an English message. No network: a $ref outside the given schema fails with remote_ref (inline it under $defs). "format" is only an annotation unless validateFormats is true. $dynamicRef is not supported (reported as a warning). Runs locally.

Parameters:
- schema (string or object or boolean, required): The JSON Schema, as JSON text or object.
- data (string or object or array or number or boolean or null, required): The instance to validate. A string is parsed as JSON, so pass "\"text\"" to validate a JSON string.
- draft (string: auto | 2020-12 | 2019-09 | 7 | 4, default "auto")
- allErrors (boolean, default true): false stops at the first error.
- validateFormats (boolean, default false): Check "format" (date, date-time, time, duration, email, hostname, ipv4, ipv6, uri, uri-reference, uri-template, uuid, regex, json-pointer).

Example input: `{"schema":"{\"type\":\"object\",\"required\":[\"name\"],\"properties\":{\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"integer\",\"minimum\":0}}}","data":"{\"name\":\"Ada\",\"age\":36}","draft":"auto"}`

Deep link (options in the query, user data after #): https://notadevblog.com/en/tools/developer/json-schema-validator/?draft=auto#schema=%7B%22type%22%3A%22object%22%2C%22required%22%3A%5B%22name%22%5D%2C%22properties%22%3A%7B%22name%22%3A%7B%22type%22%3A%22string%22%7D%2C%22age%22%3A%7B%22type%22%3A%22integer%22%2C%22minimum%22%3A0%7D%7D%7D&data=%7B%22name%22%3A%22Ada%22%2C%22age%22%3A36%7D

## How to use

1. **Paste the schema:** Put your JSON Schema on the left. The draft is read from $schema; without it, 2020-12 applies. You can also pick a draft yourself.
2. **Paste the data:** Put the JSON you want to check on the right. The result updates while you type.
3. **Read the errors:** Each error names the failing value as a JSON Pointer into your data, the schema keyword and the path to it in the schema.

## About this tool

JSON Schema describes what valid JSON looks like: types, required fields, value ranges, patterns. APIs, configuration files and tool definitions for AI agents use it to catch wrong data before it causes trouble.

Validation uses @cfworker/json-schema, which needs no eval or generated code. Error messages come from that library and are in English.

## Frequently asked questions

### Which draft is used?

The one named in $schema; without $schema, 2020-12. Draft 6 is checked as draft 7, which only adds keywords to it. Pick a draft manually to override $schema.

### Why does a $ref to a URL fail?

Remote schemas are never fetched, so the result never depends on another server. Copy the referenced schema into $defs and point the $ref to #/$defs/name.

### Why does "format": "email" accept anything?

Since draft 2019-09, format is an annotation unless a validator is told to check it. Turn on “Check formats” to validate date, date-time, email, uri, uuid, ipv4, ipv6 and more.

### What do the two paths in an error mean?

The data path is a JSON Pointer to the failing value, such as /items/2/price. The schema path leads to the keyword that failed, including every $ref it followed.

### Can the schema contain comments?

No, a JSON Schema is plain JSON. The JSON Formatter’s “Clean” mode removes comments and trailing commas for you.
