About this tool
A JSON validator tells you whether text is JSON at all. A JSON Schema validator checks whether valid JSON has the right shape: the required fields are present, values have the right types, strings match their formats and patterns, and numbers fall in range. Paste a schema on the left and your data on the right; every problem is listed with the path to the bad value and the rule it breaks.
How to validate JSON against a schema
- Paste your JSON Schema on the left. Its
$schemakeyword selects the draft; you can also choose one. - Paste the JSON to check on the right.
- Results update as you type. Each error shows the data path (for example
$.address.country), the failing keyword (such aspatternorrequired), a readable message, and where the rule is in the schema.
What is supported
- Drafts: 2020-12, 2019-09, draft-07, draft-06 and draft-04, including their differences (for example
prefixItemsversus tupleitems, and boolean versus numericexclusiveMaximum). - Keywords:
type,enum,const, number and string limits,pattern,format, array and object rules,required,additionalProperties,patternProperties,propertyNames,dependentRequired,dependentSchemas,allOf,anyOf,oneOf,not,if/then/else,unevaluatedPropertiesandunevaluatedItems. - References:
$refto$defs,definitions, JSON Pointers,$anchorand embedded$ids. References to other files or URLs aren’t fetched; paste those schemas into$defs. - Formats:
date-time,date,time,email,hostname,ipv4,ipv6,uri,uri-reference,uuid,regexandjson-pointer. Format checks can be turned off, matching validators that treatformatas an annotation only.
Reading oneOf and anyOf errors
When data fails oneOf or anyOf, every branch failed (or, for oneOf, more than one matched). The message includes the error from the closest branch, which is usually the one you meant. A frequent oneOf surprise is data matching two branches; add required or const to make the branches mutually exclusive.
Validate in your code
// npm install ajv ajv-formats
import Ajv2020 from 'ajv/dist/2020.js';
import addFormats from 'ajv-formats';
const ajv = new Ajv2020({ allErrors: true });
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);# pip install jsonschema
from jsonschema import Draft202012Validator
validator = Draft202012Validator(schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
for error in validator.iter_errors(data):
print(error.json_path, error.message)Don’t have a schema yet? Generate one from example data with the JSON Schema generator, then tighten it.
FAQ
How do I validate JSON against a schema?
Paste the JSON Schema on the left and the JSON data on the right. The validator lists every error with the data path, the failing keyword and a message, or confirms that the data is valid.
Which JSON Schema drafts are supported?
Draft 2020-12, 2019-09, draft-07, draft-06 and draft-04. The draft is detected from the $schema keyword, or you can choose one.
Why is “format” not causing errors in my other validator?
The JSON Schema spec makes format checking optional, and many validators (including Ajv without ajv-formats) ignore it by default. This tool checks formats unless you turn the option off.
Does it support $ref?
Yes, for references inside the schema: $defs, definitions, JSON Pointers, $anchor and embedded $id. References to other files or URLs are reported instead of fetched; copy those schemas into $defs.
What is the difference between additionalProperties and unevaluatedProperties?
additionalProperties only knows about properties and patternProperties in the same schema object. unevaluatedProperties (2019-09+) also counts properties validated by allOf, anyOf, oneOf, if/then/else and $ref, so it works when you combine schemas.
Is my data sent anywhere?
No. Validation runs in your browser.