jsonschema upgrade <schema.json|.yaml> [--to/-t draft4|draft6|draft7|2019-09|2020-12]
[--meta/-m] [--http/-h] [--verbose/-v] [--debug/-g] [--json/-j]
[--header/-H "<name>: <value>"]
[--resolve/-r <schemas-or-directories> ...]
[--default-dialect/-d <uri>]JSON Schema dialects are not always backwards compatible. The upgrade command
rewrites a schema to conform to a newer dialect, taking every subtletly across
specifications into account, including re-writing references that point at
locations whose path has changed. By default, schemas are upgraded to the
latest supported dialect, and the result is printed to standard output.
For example, consider the following Draft 3 schema:
{
"$schema": "http://json-schema.org/draft-03/schema#",
"id": "https://example.com",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1, "required": true },
"born": { "$ref": "#/definitions/year" }
},
"definitions": {
"year": { "type": "integer", "minimum": 1900, "divisibleBy": 1 }
}
}You can upgrade it to JSON Schema 2020-12 as follows:
jsonschema upgrade path/to/schema.json --to 2020-12The result will be something like this:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com",
"type": "object",
"required": [ "name" ],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"born": {
"$ref": "#/$defs/year"
}
},
"$defs": {
"year": {
"type": "integer",
"minimum": 1900,
"multipleOf": 1
}
}
}Warning
We don't support upgrading schemas with custom meta-schemas, as both the schema and its meta-schema would need to be upgraded together.
Note
The --to/-t option means "upgrade to at least this dialect". If your
schema is already at or beyond the target dialect, the command leaves
the schema unchanged. For example, asking the CLI to upgrade a 2020-12
schema to Draft 7 will do nothing.
Note
Pass --meta/-m when the input schema is itself a meta-schema (a schema
intended to describe other schemas). From JSON Schema 2019-09 onwards,
meta-schemas are required to declare a $vocabulary keyword. When the
flag is set, the upgrade synthesizes the standard $vocabulary block
for the target dialect at the document root if one is not already
present. This is mainly relevant when upgrading from Draft 7 to
2019-09 (or transitively to 2020-12).
jsonschema upgrade path/to/schema.jsonjsonschema upgrade path/to/schema.json --to draft7cat path/to/schema.json | jsonschema upgrade -jsonschema upgrade path/to/schema.json \
--default-dialect http://json-schema.org/draft-04/schema#jsonschema upgrade path/to/schema.json \
--resolve path/to/imported.jsonjsonschema upgrade path/to/schema.yamljsonschema upgrade path/to/metaschema.json --to 2019-09 --meta