Validate JSON data with a JSON Schema validator
This JSON Schema validator checks a JSON document against a schema and tells you exactly where the two disagree. It runs the Ajv engine with the ajv-formats plugin, so keywords such as required, enum, minItems, uniqueItems and additionalProperties are enforced, and string formats like email, date, uri and uuid are actually checked rather than ignored.
Use it while designing an API contract, when a request body is rejected and you want to know why, or to confirm that a config file matches the schema your application expects.
What is JSON Schema?
JSON Schema is a JSON vocabulary that describes the shape of other JSON: which properties exist, their types, which are mandatory, and what values are allowed. A schema is itself a JSON document, which is why this page has two editors: one for the data and one for the rules.
Schemas are used by OpenAPI, editor autocompletion (VS Code reads a $schema key), form generators and test suites. Validation is the step that turns the description into a pass or fail result.
Example
Here the schema requires an integer id, a valid email, a name and unique tags. The data breaks all four rules:
{"id": "42", "email": "jane@example", "tags": ["a", "a"]}
With Report all errors on, the result reads:
✘ 4 validation errors (2020-12):
1. (root) must have required property 'name'
line ~1 · rule #/required
2. /id must be integer
line ~1 · rule #/properties/id/type · value "42"
3. /email must match format "email"
line ~1 · rule #/properties/email/format · value "jane@example"
4. /tags must NOT have duplicate items (items ## 0 and 1 are identical)
line ~1 · rule #/properties/tags/uniqueItems
Each entry gives the instance path (where in your data), an approximate line number, the schema path of the rule that failed, and the rejected value for scalars. When everything passes you get a single line confirming the document is valid and naming the draft used.
Draft detection and options
- Draft selection: the validator reads your schema's
$schemaURL. A URL containing2020-12uses the 2020-12 dialect,2019-09uses 2019-09, and anything else (including no$schema) is validated as draft-07. Draft-06 schemas work under draft-07; draft-04 schemas are validated with draft-07 rules, which matters mainly for the old boolean form ofexclusiveMinimum. - Report all errors: on by default. Turn it off to get only the first failure, which is how many production validators behave.
- Relaxed strict mode: unknown keywords such as
exampleor customx-annotations are ignored instead of rejected, so OpenAPI-flavored schemas still compile.
Common errors and fixes
- "The schema itself is invalid" means the schema breaks the meta-schema, for example
"type": "text"or"required": "id"instead of an array. Fix the schema before looking at the data. - must NOT have additional properties appears when
additionalPropertiesisfalseand your data has a key the schema does not list. The message names the extra key. - A string number fails
"type": "integer"."42"and42are different types in JSON Schema; nothing is coerced. - Dates like
1990-02-30failformat: datebecause ajv-formats checks that the day exists, not just the pattern. - Remote
$refURLs are not downloaded. Keep referenced definitions inside the same schema under$defsordefinitions.
Related tools
If you do not have a schema yet, generate a first draft from a sample document with JSON to JSON Schema, then tighten it here. To see what data your schema accepts, create realistic samples with the JSON Schema faker. For plain syntax checking without a schema, use the JSON validator.
Privacy
Validation runs entirely in your browser. Neither your data nor your schema is uploaded, so you can safely check payloads that contain customer records or internal API contracts.
JSON Schema validator in Python
Python has no JSON Schema support in the standard library; the jsonschema package is the usual choice. jsonschema.validate() raises on the first problem only, so to list every error, create a validator for your draft and loop over iter_errors(). Also note that format keywords such as email and date are not enforced unless you pass format_checker=FormatChecker() to the validator.
# pip install jsonschema
from jsonschema import Draft202012Validator
schema = {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {"type": "integer"},
"tags": {"type": "array", "uniqueItems": True},
},
}
data = {"id": "42", "tags": ["a", "a"]}
validator = Draft202012Validator(schema)
errors = list(validator.iter_errors(data))
for error in errors:
print(error.json_path, "-", error.message)
print("valid" if not errors else f"{len(errors)} errors")
The validator above reports the same three failures for this data and schema, with the line and rule for each, which makes it a quick way to test a schema before it goes into code.