How to validate JSON against a schema
A JSON Schema is a set of rules for a JSON document: which keys are required, what type each value has, which numbers and text lengths are allowed. To validate JSON against a schema, paste both and the tool runs a standards-compliant validator, Ajv, in your browser. Nothing is uploaded, which matters when the data comes from production.
The validator reports every rule that fails, not only the first, so one pass shows you the whole list of fixes. The checks run as you type. The Privacy Policy explains what stays on your device.
Draft 2020-12: 0 valid, 1 invalid, 4 errors in 1 document.
Document 1 (line 1): 4 errors
/extra (line 5, column 3) [additionalProperties]: Unexpected property "extra" in the document. The schema does not allow extra properties. Remove "extra", or allow extra properties in the schema.
/id (line 2, column 9) [minimum]: /id must be at least 1 but is 0. Change the number to fit the range.
/email (line 3, column 12) [format]: "ana-at-example.com" at /email is not a valid email. Use a value in email format.
/role (line 4, column 11) [enum]: "owner" at /role is not one of the allowed values: "admin", "user".Errors with paths, lines and columns
Each error carries a JSON Pointer such as /users/3/email, which names the exact value. The tool also maps the pointer back to the text you pasted, so you get a line and a column. A missing required property points at the object that lacks it, and an unexpected property points at its key.
The messages are written for people. Instead of must have required property, you read Missing required property "age" in the document, and the hint says what to change. The raw keyword, such as minimum or enum, is shown too, so you can find the rule in the schema.
When a document has more than 100 errors, the list and the copied report show the first 100, followed by how many were left out. The counts include all of them.
JSON Schema draft 2020-12, 2019-09, 07, 06 and 04
The draft is taken from the $schema keyword. If the schema has none, 2020-12 is used. Choose a draft from the list to override it, and the tool notes that the $schema value was ignored. A $schema value that is not a known draft is ignored the same way.
- 2020-12 and 2019-09 support prefixItems, dependentRequired, unevaluatedProperties and $defs.
- Draft 07 and 06 use definitions and items arrays for tuples. Draft 06 added const and contains.
- Draft 04 uses boolean exclusiveMinimum and exclusiveMaximum next to minimum and maximum.
Before it checks any data, the tool checks the schema itself against the meta-schema of the chosen draft, so a typo such as type: strin is reported as a schema problem instead of passing silently.
Format checks
By default JSON Schema treats format as a hint, so a bad email passes. Turn on Check formats and the validator tests the common ones: date-time, date, time, email, hostname, ipv4, ipv6, uri, uuid, regex and more. Leave it off to check structure only.
Validate JSON Lines in bulk
Turn on Several documents and the data box can hold many JSON values, one per line or one after another. Each is checked on its own. The result shows how many passed and failed, and a table lists each document with its starting line and error count. Press a document to see its errors. Only invalid is on by default, so a long file shows just the problems.
The report you copy lists every failing document, which suits a log of a data feed. To look through a large file first, JSONL Viewer shows its records.
References with $ref and $defs
References inside the schema, such as #/$defs/address or #/definitions/address, are resolved, including recursive ones. A schema that points to another file with $ref needs that file in the Referenced schemas box. Paste each extra schema there with its own $id and the reference is found. The validator never fetches anything from the network.
If a reference cannot be found, the message names it and says where to define it.
Limits and related tools
- Keywords that the chosen draft does not know are ignored, as the specification says.
- Regular expressions in pattern use JavaScript syntax.
- A batch can hold up to 200,000 documents, and the input is limited to 2 million characters.
- The validator checks data against a schema. It does not edit the schema.
- A property that is named __proto__ is not handled correctly by the underlying validator, so avoid that name in schemas and data.
If you do not have a schema yet, the JSON Schema Generator makes one from your samples, and the button above the boxes sends your data to it. JSON to YAML and Sort JSON Keys help tidy a schema file.