jsonschema lint [schemas-or-directories...]
[--fix/-f] [--verbose/-v] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
JSON Schema is a surprisingly expressive schema language. Like with traditional
programming languages, writing efficient and maintainable schemas takes
experience, and there are lots of common pitfalls. Just like popular linters
like ESLint,
ClangTidy, and
PyLint, the JSON Schema CLI provides a lint
command
that can check your schemas against various common anti-patterns and
automatically fix many of them.
For example, consider the following schema that asserts that the JSON instance
is the string foo
:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"enum": [ "foo" ]
}
While this schema is technically correct, the JSON Schema 2020-12 dialect has a
const
keyword
that better expresses the intention of matching a single possible value.
Running the JSON Schema CLI linter against the previous schema will produce the following output:
$ jsonschema lint schema.json
schema.json
An `enum` of a single value can be expressed as `const` (enum_to_const)
Furthermore, running the lint
command with the --fix / -f
option will
result in the JSON Schema CLI automatically fixing the warning for you.
jsonschema lint path/to/my/schema_1.json path/to/my/schema_2.json
jsonschema lint path/to/schemas/
jsonschema lint path/to/schemas/ --ignore path/to/schemas/nested
jsonschema lint
jsonschema lint --extension .schema.json
jsonschema lint path/to/my/schema.json --fix