Warning
JSON Schema Draft 3 and older are not supported at this point in time.
jsonschema validate <schema.json|.yaml> <instance.json|.jsonl|.yaml|directory...>
[--http/-h] [--verbose/-v] [--debug/-g]
[--resolve/-r <schemas-or-directories> ...]
[--benchmark/-b] [--loop <iterations>] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>] [--trace/-t] [--fast/-f]
[--template/-m <template.json>] [--json/-j] [--entrypoint/-p <pointer|uri>]The most popular use case of JSON Schema is to validate JSON documents. The
JSON Schema CLI offers a validate command to evaluate one or many JSON
instances, directories of instances, or JSONL datasets against a JSON Schema,
presenting human-friendly information on unsuccessful validation.
The --json/-j option outputs the evaluation result using the JSON Schema
Flag or
Basic
standard format depending on whether the --fast/-f option is set.
If you want to validate that a schema adheres to its metaschema, use the
metaschema command instead.
To help scripts distinguish validation errors, these are reported using exit code 2.
Note
Annotations are only printed when passing the --verbose/-v or the
--trace/-t options. However, annotation collection will be skipped if the
--fast/-f option is passed.
Warning
By default, schemas are validated in exhaustive mode, which results in better
error messages, at the expense of speed. The --fast/-f option makes the
schema compiler optimise for speed, at the expense of error messages.
To speed-up the compilation process, you may pre-compile a schema using the
compile command and pass the result using the
--template/-m option. However, you still need to pass the original schema
for error reporting purposes. Make sure they match and that the compilation and
evaluation were done with the same version of this tool or you might get
non-sense results.
Tip
Templates produced by the compile command can
also be evaluated from JavaScript using the Blaze JavaScript
port, a
pure-JavaScript evaluator for browsers and JavaScript runtimes like
Node.js, letting you compile with this CLI and validate anywhere.
Warning
This tool (and its underlying Blaze
evaluator) does not support turning on
format
validation in JSON Schema 2019-09 and older (an optional feature as per the
specification), nor the optional JSON Schema 2020-12
format-assertion
vocabulary (which has seen extremely little adoption in the wild). Over time,
format optional validation proved to be inconsistent across implementations
and led to significant confusion in the community. We strongly suggest you
treat
format
as an annotation and explicitly validate strings with the less ambiguous
pattern
keyword, if needed.
For example, consider the following JSON Schema Draft 4 schema that asserts that the JSON instance is a string:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "string"
}Also consider a JSON instance called instance.json that looks like this:
12345This instance is an integer, while the given schema expects a string. Validating the instance against the schema using the JSON Schema CLI will result in the following output:
$ jsonschema validate schema.json instance.json
error: The target document is expected to be of the given type
at instance location ""
at evaluate path "/type"jsonschema validate path/to/my/schema.json path/to/my/instance.jsonjsonschema validate path/to/my/schema.json path/to/my/instance.json --jsonjsonschema compile path/to/my/schema.json > template.json
jsonschema validate path/to/my/schema.json path/to/my/instance.json \
--template template.jsonjsonschema validate path/to/my/schema.json path/to/my/instance.json --fastjsonschema validate path/to/my/schema.json \
path/to/my/instance_1.json \
path/to/my/instance_2.json \
path/to/my/instance_3.jsonjsonschema validate path/to/my/schema.json path/to/my/dataset.jsonljsonschema validate path/to/my/schema.json path/to/my/instance.json --httpjsonschema validate path/to/my/schema.json path/to/my/instance.json \
--resolve path/to/external.jsonjsonschema validate path/to/my/schema.json path/to/my/instance.json \
--resolve path/to/schemas --extension schema.jsonjsonschema validate path/to/my/schema.json path/to/my/instance.json --benchmarkjsonschema validate path/to/my/schema.json path/to/my/instance.json --tracejsonschema validate path/to/my/schema.json path/to/instances/jsonschema validate path/to/my/schema.json path/to/instances/ --extension .data.jsonjsonschema validate path/to/my/schema.json path/to/instances/ \
--ignore path/to/instances/draftsjsonschema validate path/to/my/schema.json path/to/my/instance.json \
--entrypoint '/$defs/MyType'