Warning
JSON Schema Draft 3 and older are not supported at this point in time.
jsonschema validate <schema.json|.yaml> <instance.json|.jsonl|.yaml...> [--http/-h]
[--verbose/-v] [--resolve/-r <schemas-or-directories> ...] [--benchmark/-b]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>] [--trace/-t]
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 or JSONL datasets against a JSON Schema, presenting human-friendly
information on unsuccessful validation.
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.
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:
12345
This 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.json
jsonschema validate path/to/my/schema.json \
path/to/my/instance_1.json \
path/to/my/instance_2.json \
path/to/my/instance_3.json
jsonschema validate path/to/my/schema.json path/to/my/dataset.jsonl
jsonschema validate path/to/my/schema.json path/to/my/instance.json --http
jsonschema validate path/to/my/schema.json path/to/my/instance.json \
--resolve path/to/external.json
jsonschema validate path/to/my/schema.json path/to/my/instance.json \
--resolve path/to/schemas --extension schema.json
jsonschema validate path/to/my/schema.json path/to/my/instance.json --benchmark
jsonschema validate path/to/my/schema.json path/to/my/instance.json --trace