jsonschema fmt [schemas-or-directories...]
[--check/-c] [--verbose/-v] [--debug/-g]
[--resolve/-r <schemas-or-directories> ...]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>]
[--keep-ordering/-k] [--indentation/-n <spaces>] [--default-dialect/-d <uri>]
[--json/-j]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.
This command does not support YAML schemas yet.
For example, consider this fictitious JSON Schema with inconsistent indentation, 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.jsonjsonschema fmt path/to/my/schema_1.json path/to/my/schema_2.json --keep-orderingjsonschema fmt path/to/my/schema_1.json path/to/my/schema_2.json --indentation 4jsonschema fmt path/to/schemas/jsonschema fmtjsonschema fmt path/to/schemas/ --ignore path/to/schemas/nestedjsonschema fmt --extension .schema.jsonjsonschema fmt path/to/my/schema.json --check