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] [--configuration/-C <path>] [--color auto|always|never]Note
See Resolving External References for every way of making referenced schemas available, including how to handle a reference whose URI differs from the identifier the target schema declares.
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.
If the input is an OpenAPI spec v3.1 or v3.2, the fmt command treats it as an
OpenAPI description rather than as
a schema. The fields of the description are ordered following an OpenAPI aware
convention, and every Schema Object it holds is formatted as a schema would be.
Any other revision, such as v3.0, is rejected rather than read as a schema.
--keep-ordering/-k applies to a description as it does to a schema, leaving
every key where it was written.
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 --checkjsonschema fmt path/to/my/openapi.json