jsonschema fmt [schemas-or-directories...]
[--check/-c] [--verbose/-v] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
Schemas are code. As such, they are expected follow consistent stylistic
conventions. Just as code-formatters like
clang-format, JavaScript's
prettier, and
rustfmt, the JSON Schema CLI offers a
fmt
command to format schemas based on industry-standard conventions and to
check their adherence on a continuous integration environment.
For example, consider this fictitious JSON Schema with inconsistent identation, spacing, keyword ordering, and more:
{ "$schema":"https://json-schema.org/draft/2020-12/schema",
"type": "string","pattern": "^(?!0000)\\d{4}$",
"$id": "https://example.com/iso8601/v1.json",
"title": "ISO 8601 four-digit year (YYYY)" }
After formatting it, the JSON Schema looks like this:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/iso8601/v1.json",
"title": "ISO 8601 four-digit year (YYYY)",
"type": "string",
"pattern": "^(?!0000)\\d{4}$"
}
jsonschema fmt path/to/my/schema_1.json path/to/my/schema_2.json
jsonschema fmt path/to/schemas/
jsonschema fmt
jsonschema fmt path/to/schemas/ --ignore path/to/schemas/nested
jsonschema fmt --extension .schema.json
jsonschema fmt path/to/my/schema.json --check