jsonschema.validators#

Creation and extension of validators, with implementations for existing drafts.

class jsonschema.validators.Draft201909Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['date', 'email', 'idn-email', 'idn-hostname', 'ipv4', 'ipv6', 'regex', 'uuid']>#
static ID_OF(schema)#

Return the ID of a schema for recent JSON Schema drafts.

META_SCHEMA = {'$id': 'https://json-schema.org/draft/2019-09/schema', '$recursiveAnchor': True, '$schema': 'https://json-schema.org/draft/2019-09/schema', '$vocabulary': {'https://json-schema.org/draft/2019-09/vocab/applicator': True, 'https://json-schema.org/draft/2019-09/vocab/content': True, 'https://json-schema.org/draft/2019-09/vocab/core': True, 'https://json-schema.org/draft/2019-09/vocab/format': False, 'https://json-schema.org/draft/2019-09/vocab/meta-data': True, 'https://json-schema.org/draft/2019-09/vocab/validation': True}, 'allOf': [{'$ref': 'meta/core'}, {'$ref': 'meta/applicator'}, {'$ref': 'meta/validation'}, {'$ref': 'meta/meta-data'}, {'$ref': 'meta/format'}, {'$ref': 'meta/content'}], 'properties': {'definitions': {'$comment': 'While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.', 'additionalProperties': {'$recursiveRef': '#'}, 'default': {}, 'type': 'object'}, 'dependencies': {'$comment': '"dependencies" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to "dependentSchemas" and "dependentRequired"', 'additionalProperties': {'anyOf': [{'$recursiveRef': '#'}, {'$ref': 'meta/validation#/$defs/stringArray'}]}, 'type': 'object'}}, 'title': 'Core and Validation specifications meta-schema', 'type': ['object', 'boolean']}#
TYPE_CHECKER = <TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$recursiveRef': <function recursiveRef>, '$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'allOf': <function allOf>, 'anyOf': <function anyOf>, 'const': <function const>, 'contains': <function contains>, 'dependentRequired': <function dependentRequired>, 'dependentSchemas': <function dependentSchemas>, 'enum': <function enum>, 'exclusiveMaximum': <function exclusiveMaximum>, 'exclusiveMinimum': <function exclusiveMinimum>, 'format': <function format>, 'if': <function if_>, 'items': <function items_draft6_draft7_draft201909>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maxProperties': <function maxProperties>, 'maximum': <function maximum>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minProperties': <function minProperties>, 'minimum': <function minimum>, 'multipleOf': <function multipleOf>, 'not': <function not_>, 'oneOf': <function oneOf>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'properties': <function properties>, 'propertyNames': <function propertyNames>, 'required': <function required>, 'type': <function type>, 'unevaluatedItems': <function unevaluatedItems_draft2019>, 'unevaluatedProperties': <function unevaluatedProperties>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.Draft202012Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['date', 'email', 'idn-email', 'idn-hostname', 'ipv4', 'ipv6', 'regex', 'uuid']>#
static ID_OF(schema)#

Return the ID of a schema for recent JSON Schema drafts.

META_SCHEMA = {'$comment': 'This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.', '$dynamicAnchor': 'meta', '$id': 'https://json-schema.org/draft/2020-12/schema', '$schema': 'https://json-schema.org/draft/2020-12/schema', '$vocabulary': {'https://json-schema.org/draft/2020-12/vocab/applicator': True, 'https://json-schema.org/draft/2020-12/vocab/content': True, 'https://json-schema.org/draft/2020-12/vocab/core': True, 'https://json-schema.org/draft/2020-12/vocab/format-annotation': True, 'https://json-schema.org/draft/2020-12/vocab/meta-data': True, 'https://json-schema.org/draft/2020-12/vocab/unevaluated': True, 'https://json-schema.org/draft/2020-12/vocab/validation': True}, 'allOf': [{'$ref': 'meta/core'}, {'$ref': 'meta/applicator'}, {'$ref': 'meta/unevaluated'}, {'$ref': 'meta/validation'}, {'$ref': 'meta/meta-data'}, {'$ref': 'meta/format-annotation'}, {'$ref': 'meta/content'}], 'properties': {'$recursiveAnchor': {'$comment': '"$recursiveAnchor" has been replaced by "$dynamicAnchor".', '$ref': 'meta/core#/$defs/anchorString', 'deprecated': True}, '$recursiveRef': {'$comment': '"$recursiveRef" has been replaced by "$dynamicRef".', '$ref': 'meta/core#/$defs/uriReferenceString', 'deprecated': True}, 'definitions': {'$comment': '"definitions" has been replaced by "$defs".', 'additionalProperties': {'$dynamicRef': '#meta'}, 'default': {}, 'deprecated': True, 'type': 'object'}, 'dependencies': {'$comment': '"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.', 'additionalProperties': {'anyOf': [{'$dynamicRef': '#meta'}, {'$ref': 'meta/validation#/$defs/stringArray'}]}, 'default': {}, 'deprecated': True, 'type': 'object'}}, 'title': 'Core and Validation specifications meta-schema', 'type': ['object', 'boolean']}#
TYPE_CHECKER = <TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$dynamicRef': <function dynamicRef>, '$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'allOf': <function allOf>, 'anyOf': <function anyOf>, 'const': <function const>, 'contains': <function contains>, 'dependentRequired': <function dependentRequired>, 'dependentSchemas': <function dependentSchemas>, 'enum': <function enum>, 'exclusiveMaximum': <function exclusiveMaximum>, 'exclusiveMinimum': <function exclusiveMinimum>, 'format': <function format>, 'if': <function if_>, 'items': <function items>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maxProperties': <function maxProperties>, 'maximum': <function maximum>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minProperties': <function minProperties>, 'minimum': <function minimum>, 'multipleOf': <function multipleOf>, 'not': <function not_>, 'oneOf': <function oneOf>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'prefixItems': <function prefixItems>, 'properties': <function properties>, 'propertyNames': <function propertyNames>, 'required': <function required>, 'type': <function type>, 'unevaluatedItems': <function unevaluatedItems>, 'unevaluatedProperties': <function unevaluatedProperties>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.Draft3Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['date', 'email', 'idn-email', 'ip-address', 'ipv6', 'regex', 'time']>#
static ID_OF(schema)#

Ignore an $id sibling of $ref if it is present.

Otherwise, return the ID of the given schema.

META_SCHEMA = {'$schema': 'http://json-schema.org/draft-03/schema#', 'default': {}, 'dependencies': {'exclusiveMaximum': 'maximum', 'exclusiveMinimum': 'minimum'}, 'id': 'http://json-schema.org/draft-03/schema#', 'properties': {'$ref': {'type': 'string'}, '$schema': {'format': 'uri', 'type': 'string'}, 'additionalItems': {'default': {}, 'type': [{'$ref': '#'}, 'boolean']}, 'additionalProperties': {'default': {}, 'type': [{'$ref': '#'}, 'boolean']}, 'default': {'type': 'any'}, 'dependencies': {'additionalProperties': {'items': {'type': 'string'}, 'type': ['string', 'array', {'$ref': '#'}]}, 'default': {}, 'type': 'object'}, 'description': {'type': 'string'}, 'disallow': {'items': {'type': ['string', {'$ref': '#'}]}, 'type': ['string', 'array'], 'uniqueItems': True}, 'divisibleBy': {'default': 1, 'exclusiveMinimum': True, 'minimum': 0, 'type': 'number'}, 'enum': {'minItems': 1, 'type': 'array', 'uniqueItems': True}, 'exclusiveMaximum': {'default': False, 'type': 'boolean'}, 'exclusiveMinimum': {'default': False, 'type': 'boolean'}, 'extends': {'default': {}, 'items': {'$ref': '#'}, 'type': [{'$ref': '#'}, 'array']}, 'format': {'type': 'string'}, 'id': {'type': 'string'}, 'items': {'default': {}, 'items': {'$ref': '#'}, 'type': [{'$ref': '#'}, 'array']}, 'maxItems': {'minimum': 0, 'type': 'integer'}, 'maxLength': {'type': 'integer'}, 'maximum': {'type': 'number'}, 'minItems': {'default': 0, 'minimum': 0, 'type': 'integer'}, 'minLength': {'default': 0, 'minimum': 0, 'type': 'integer'}, 'minimum': {'type': 'number'}, 'pattern': {'format': 'regex', 'type': 'string'}, 'patternProperties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'properties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'required': {'default': False, 'type': 'boolean'}, 'title': {'type': 'string'}, 'type': {'default': 'any', 'items': {'type': ['string', {'$ref': '#'}]}, 'type': ['string', 'array'], 'uniqueItems': True}, 'uniqueItems': {'default': False, 'type': 'boolean'}}, 'type': 'object'}#
TYPE_CHECKER = <TypeChecker types={'any', 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'dependencies': <function dependencies_draft3>, 'disallow': <function disallow_draft3>, 'divisibleBy': <function multipleOf>, 'enum': <function enum>, 'extends': <function extends_draft3>, 'format': <function format>, 'items': <function items_draft3_draft4>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maximum': <function maximum_draft3_draft4>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minimum': <function minimum_draft3_draft4>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'properties': <function properties_draft3>, 'type': <function type_draft3>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.Draft4Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['email', 'idn-email', 'ipv4', 'ipv6', 'regex']>#
static ID_OF(schema)#

Ignore an $id sibling of $ref if it is present.

Otherwise, return the ID of the given schema.

META_SCHEMA = {'$schema': 'http://json-schema.org/draft-04/schema#', 'default': {}, 'definitions': {'positiveInteger': {'minimum': 0, 'type': 'integer'}, 'positiveIntegerDefault0': {'allOf': [{'$ref': '#/definitions/positiveInteger'}, {'default': 0}]}, 'schemaArray': {'items': {'$ref': '#'}, 'minItems': 1, 'type': 'array'}, 'simpleTypes': {'enum': ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']}, 'stringArray': {'items': {'type': 'string'}, 'minItems': 1, 'type': 'array', 'uniqueItems': True}}, 'dependencies': {'exclusiveMaximum': ['maximum'], 'exclusiveMinimum': ['minimum']}, 'description': 'Core schema meta-schema', 'id': 'http://json-schema.org/draft-04/schema#', 'properties': {'$schema': {'type': 'string'}, 'additionalItems': {'anyOf': [{'type': 'boolean'}, {'$ref': '#'}], 'default': {}}, 'additionalProperties': {'anyOf': [{'type': 'boolean'}, {'$ref': '#'}], 'default': {}}, 'allOf': {'$ref': '#/definitions/schemaArray'}, 'anyOf': {'$ref': '#/definitions/schemaArray'}, 'default': {}, 'definitions': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'dependencies': {'additionalProperties': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/stringArray'}]}, 'type': 'object'}, 'description': {'type': 'string'}, 'enum': {'minItems': 1, 'type': 'array', 'uniqueItems': True}, 'exclusiveMaximum': {'default': False, 'type': 'boolean'}, 'exclusiveMinimum': {'default': False, 'type': 'boolean'}, 'format': {'type': 'string'}, 'id': {'type': 'string'}, 'items': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}], 'default': {}}, 'maxItems': {'$ref': '#/definitions/positiveInteger'}, 'maxLength': {'$ref': '#/definitions/positiveInteger'}, 'maxProperties': {'$ref': '#/definitions/positiveInteger'}, 'maximum': {'type': 'number'}, 'minItems': {'$ref': '#/definitions/positiveIntegerDefault0'}, 'minLength': {'$ref': '#/definitions/positiveIntegerDefault0'}, 'minProperties': {'$ref': '#/definitions/positiveIntegerDefault0'}, 'minimum': {'type': 'number'}, 'multipleOf': {'exclusiveMinimum': True, 'minimum': 0, 'type': 'number'}, 'not': {'$ref': '#'}, 'oneOf': {'$ref': '#/definitions/schemaArray'}, 'pattern': {'format': 'regex', 'type': 'string'}, 'patternProperties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'properties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'required': {'$ref': '#/definitions/stringArray'}, 'title': {'type': 'string'}, 'type': {'anyOf': [{'$ref': '#/definitions/simpleTypes'}, {'type': 'array', 'items': {'$ref': '#/definitions/simpleTypes'}, 'minItems': 1, 'uniqueItems': True}]}, 'uniqueItems': {'default': False, 'type': 'boolean'}}, 'type': 'object'}#
TYPE_CHECKER = <TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'allOf': <function allOf>, 'anyOf': <function anyOf>, 'dependencies': <function dependencies_draft4_draft6_draft7>, 'enum': <function enum>, 'format': <function format>, 'items': <function items_draft3_draft4>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maxProperties': <function maxProperties>, 'maximum': <function maximum_draft3_draft4>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minProperties': <function minProperties>, 'minimum': <function minimum_draft3_draft4>, 'multipleOf': <function multipleOf>, 'not': <function not_>, 'oneOf': <function oneOf>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'properties': <function properties>, 'required': <function required>, 'type': <function type>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.Draft6Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['email', 'idn-email', 'ipv4', 'ipv6', 'regex']>#
static ID_OF(schema)#

Ignore an $id sibling of $ref if it is present.

Otherwise, return the ID of the given schema.

META_SCHEMA = {'$id': 'http://json-schema.org/draft-06/schema#', '$schema': 'http://json-schema.org/draft-06/schema#', 'default': {}, 'definitions': {'nonNegativeInteger': {'minimum': 0, 'type': 'integer'}, 'nonNegativeIntegerDefault0': {'allOf': [{'$ref': '#/definitions/nonNegativeInteger'}, {'default': 0}]}, 'schemaArray': {'items': {'$ref': '#'}, 'minItems': 1, 'type': 'array'}, 'simpleTypes': {'enum': ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']}, 'stringArray': {'default': [], 'items': {'type': 'string'}, 'type': 'array', 'uniqueItems': True}}, 'properties': {'$id': {'format': 'uri-reference', 'type': 'string'}, '$ref': {'format': 'uri-reference', 'type': 'string'}, '$schema': {'format': 'uri', 'type': 'string'}, 'additionalItems': {'$ref': '#'}, 'additionalProperties': {'$ref': '#'}, 'allOf': {'$ref': '#/definitions/schemaArray'}, 'anyOf': {'$ref': '#/definitions/schemaArray'}, 'const': {}, 'contains': {'$ref': '#'}, 'default': {}, 'definitions': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'dependencies': {'additionalProperties': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/stringArray'}]}, 'type': 'object'}, 'description': {'type': 'string'}, 'enum': {'type': 'array'}, 'examples': {'items': {}, 'type': 'array'}, 'exclusiveMaximum': {'type': 'number'}, 'exclusiveMinimum': {'type': 'number'}, 'format': {'type': 'string'}, 'items': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}], 'default': {}}, 'maxItems': {'$ref': '#/definitions/nonNegativeInteger'}, 'maxLength': {'$ref': '#/definitions/nonNegativeInteger'}, 'maxProperties': {'$ref': '#/definitions/nonNegativeInteger'}, 'maximum': {'type': 'number'}, 'minItems': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minLength': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minProperties': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minimum': {'type': 'number'}, 'multipleOf': {'exclusiveMinimum': 0, 'type': 'number'}, 'not': {'$ref': '#'}, 'oneOf': {'$ref': '#/definitions/schemaArray'}, 'pattern': {'format': 'regex', 'type': 'string'}, 'patternProperties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'propertyNames': {'format': 'regex'}, 'type': 'object'}, 'properties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'propertyNames': {'$ref': '#'}, 'required': {'$ref': '#/definitions/stringArray'}, 'title': {'type': 'string'}, 'type': {'anyOf': [{'$ref': '#/definitions/simpleTypes'}, {'type': 'array', 'items': {'$ref': '#/definitions/simpleTypes'}, 'minItems': 1, 'uniqueItems': True}]}, 'uniqueItems': {'default': False, 'type': 'boolean'}}, 'title': 'Core schema meta-schema', 'type': ['object', 'boolean']}#
TYPE_CHECKER = <TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'allOf': <function allOf>, 'anyOf': <function anyOf>, 'const': <function const>, 'contains': <function contains_draft6_draft7>, 'dependencies': <function dependencies_draft4_draft6_draft7>, 'enum': <function enum>, 'exclusiveMaximum': <function exclusiveMaximum>, 'exclusiveMinimum': <function exclusiveMinimum>, 'format': <function format>, 'items': <function items_draft6_draft7_draft201909>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maxProperties': <function maxProperties>, 'maximum': <function maximum>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minProperties': <function minProperties>, 'minimum': <function minimum>, 'multipleOf': <function multipleOf>, 'not': <function not_>, 'oneOf': <function oneOf>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'properties': <function properties>, 'propertyNames': <function propertyNames>, 'required': <function required>, 'type': <function type>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.Draft7Validator(schema, resolver=None, format_checker=None)#
FORMAT_CHECKER = <FormatChecker checkers=['date', 'email', 'idn-email', 'idn-hostname', 'ipv4', 'ipv6', 'regex']>#
static ID_OF(schema)#

Ignore an $id sibling of $ref if it is present.

Otherwise, return the ID of the given schema.

META_SCHEMA = {'$id': 'http://json-schema.org/draft-07/schema#', '$schema': 'http://json-schema.org/draft-07/schema#', 'default': True, 'definitions': {'nonNegativeInteger': {'minimum': 0, 'type': 'integer'}, 'nonNegativeIntegerDefault0': {'allOf': [{'$ref': '#/definitions/nonNegativeInteger'}, {'default': 0}]}, 'schemaArray': {'items': {'$ref': '#'}, 'minItems': 1, 'type': 'array'}, 'simpleTypes': {'enum': ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string']}, 'stringArray': {'default': [], 'items': {'type': 'string'}, 'type': 'array', 'uniqueItems': True}}, 'properties': {'$comment': {'type': 'string'}, '$id': {'format': 'uri-reference', 'type': 'string'}, '$ref': {'format': 'uri-reference', 'type': 'string'}, '$schema': {'format': 'uri', 'type': 'string'}, 'additionalItems': {'$ref': '#'}, 'additionalProperties': {'$ref': '#'}, 'allOf': {'$ref': '#/definitions/schemaArray'}, 'anyOf': {'$ref': '#/definitions/schemaArray'}, 'const': True, 'contains': {'$ref': '#'}, 'contentEncoding': {'type': 'string'}, 'contentMediaType': {'type': 'string'}, 'default': True, 'definitions': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'dependencies': {'additionalProperties': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/stringArray'}]}, 'type': 'object'}, 'description': {'type': 'string'}, 'else': {'$ref': '#'}, 'enum': {'items': True, 'type': 'array'}, 'examples': {'items': True, 'type': 'array'}, 'exclusiveMaximum': {'type': 'number'}, 'exclusiveMinimum': {'type': 'number'}, 'format': {'type': 'string'}, 'if': {'$ref': '#'}, 'items': {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}], 'default': True}, 'maxItems': {'$ref': '#/definitions/nonNegativeInteger'}, 'maxLength': {'$ref': '#/definitions/nonNegativeInteger'}, 'maxProperties': {'$ref': '#/definitions/nonNegativeInteger'}, 'maximum': {'type': 'number'}, 'minItems': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minLength': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minProperties': {'$ref': '#/definitions/nonNegativeIntegerDefault0'}, 'minimum': {'type': 'number'}, 'multipleOf': {'exclusiveMinimum': 0, 'type': 'number'}, 'not': {'$ref': '#'}, 'oneOf': {'$ref': '#/definitions/schemaArray'}, 'pattern': {'format': 'regex', 'type': 'string'}, 'patternProperties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'propertyNames': {'format': 'regex'}, 'type': 'object'}, 'properties': {'additionalProperties': {'$ref': '#'}, 'default': {}, 'type': 'object'}, 'propertyNames': {'$ref': '#'}, 'readOnly': {'default': False, 'type': 'boolean'}, 'required': {'$ref': '#/definitions/stringArray'}, 'then': {'$ref': '#'}, 'title': {'type': 'string'}, 'type': {'anyOf': [{'$ref': '#/definitions/simpleTypes'}, {'type': 'array', 'items': {'$ref': '#/definitions/simpleTypes'}, 'minItems': 1, 'uniqueItems': True}]}, 'uniqueItems': {'default': False, 'type': 'boolean'}}, 'title': 'Core schema meta-schema', 'type': ['object', 'boolean']}#
TYPE_CHECKER = <TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>#
VALIDATORS = {'$ref': <function ref>, 'additionalItems': <function additionalItems>, 'additionalProperties': <function additionalProperties>, 'allOf': <function allOf>, 'anyOf': <function anyOf>, 'const': <function const>, 'contains': <function contains_draft6_draft7>, 'dependencies': <function dependencies_draft4_draft6_draft7>, 'enum': <function enum>, 'exclusiveMaximum': <function exclusiveMaximum>, 'exclusiveMinimum': <function exclusiveMinimum>, 'format': <function format>, 'if': <function if_>, 'items': <function items_draft6_draft7_draft201909>, 'maxItems': <function maxItems>, 'maxLength': <function maxLength>, 'maxProperties': <function maxProperties>, 'maximum': <function maximum>, 'minItems': <function minItems>, 'minLength': <function minLength>, 'minProperties': <function minProperties>, 'minimum': <function minimum>, 'multipleOf': <function multipleOf>, 'not': <function not_>, 'oneOf': <function oneOf>, 'pattern': <function pattern>, 'patternProperties': <function patternProperties>, 'properties': <function properties>, 'propertyNames': <function propertyNames>, 'required': <function required>, 'type': <function type>, 'uniqueItems': <function uniqueItems>}#
classmethod check_schema(schema, format_checker=<unset>)#
descend(instance, schema, path=None, schema_path=None)#
evolve(**changes)#
is_type(instance, type)#
is_valid(instance, _schema=None)#
iter_errors(instance, _schema=None)#
validate(*args, **kwargs)#
class jsonschema.validators.RefResolver(base_uri, referrer, store=pmap({}), cache_remote=True, handlers=(), urljoin_cache=None, remote_cache=None)[source]#

Resolve JSON References.

Parameters:
  • base_uri (str) – The URI of the referring document

  • referrer – The actual referring document

  • store (dict) – A mapping from URIs to documents to cache

  • cache_remote (bool) – Whether remote refs should be cached after first resolution

  • handlers (dict) – A mapping from URI schemes to functions that should be used to retrieve them

  • urljoin_cache (functools.lru_cache()) – A cache that will be used for caching the results of joining the resolution scope to subscopes.

  • remote_cache (functools.lru_cache()) – A cache that will be used for caching the results of resolved remote URLs.

cache_remote#

Whether remote refs should be cached after first resolution

Type:

bool

property base_uri#

Retrieve the current base URI, not including any fragment.

classmethod from_schema(schema, id_of=<function _id_of>, *args, **kwargs)[source]#

Construct a resolver from a JSON schema object.

Parameters:

schema – the referring schema

Returns:

RefResolver

in_scope(scope)[source]#

Temporarily enter the given scope for the duration of the context.

Deprecated since version v4.0.0.

pop_scope()[source]#

Exit the most recent entered scope.

Treats further dereferences as being performed underneath the original scope.

Don’t call this method more times than push_scope has been called.

push_scope(scope)[source]#

Enter a given sub-scope.

Treats further dereferences as being performed underneath the given scope.

property resolution_scope#

Retrieve the current resolution scope.

resolve(ref)[source]#

Resolve the given reference.

resolve_fragment(document, fragment)[source]#

Resolve a fragment within the referenced document.

Parameters:
  • document – The referent document

  • fragment (str) – a URI fragment to resolve within it

resolve_from_url(url)[source]#

Resolve the given URL.

resolve_remote(uri)[source]#

Resolve a remote uri.

If called directly, does not check the store first, but after retrieving the document at the specified URI it will be saved in the store if cache_remote is True.

Note

If the requests library is present, jsonschema will use it to request the remote uri, so that the correct encoding is detected and used.

If it isn’t, or if the scheme of the uri is not http or https, UTF-8 is assumed.

Parameters:

uri (str) – The URI to resolve

Returns:

The retrieved document

resolving(ref)[source]#

Resolve the given ref and enter its resolution scope.

Exits the scope on exit of this context manager.

Parameters:

ref (str) – The reference to resolve

jsonschema.validators.create(meta_schema, validators=(), version=None, type_checker=<TypeChecker types={'array', 'boolean', 'integer', 'null', 'number', 'object', 'string'}>, format_checker=<FormatChecker checkers=['date', 'email', 'idn-email', 'idn-hostname', 'ipv4', 'ipv6', 'regex', 'uuid']>, id_of=<function _id_of>, applicable_validators=operator.methodcaller('items'))[source]#

Create a new validator class.

Parameters:
  • meta_schema (collections.abc.Mapping) – the meta schema for the new validator class

  • validators (collections.abc.Mapping) –

    a mapping from names to callables, where each callable will validate the schema property with the given name.

    Each callable should take 4 arguments:

    1. a validator instance,

    2. the value of the property being validated within the instance

    3. the instance

    4. the schema

  • version (str) – an identifier for the version that this validator class will validate. If provided, the returned validator class will have its __name__ set to include the version, and also will have jsonschema.validators.validates automatically called for the given version.

  • type_checker (jsonschema.TypeChecker) –

    a type checker, used when applying the type keyword.

    If unprovided, a jsonschema.TypeChecker will be created with a set of default types typical of JSON Schema drafts.

  • format_checker (jsonschema.FormatChecker) –

    a format checker, used when applying the format keyword.

    If unprovided, a jsonschema.FormatChecker will be created with a set of default formats typical of JSON Schema drafts.

  • id_of (collections.abc.Callable) – A function that given a schema, returns its ID.

  • applicable_validators (collections.abc.Callable) – A function that given a schema, returns the list of applicable validators (validation keywords and callables) which will be used to validate the instance.

Returns:

a new jsonschema.protocols.Validator class

jsonschema.validators.extend(validator, validators=(), version=None, type_checker=None, format_checker=None)[source]#

Create a new validator class by extending an existing one.

Parameters:
  • validator (jsonschema.protocols.Validator) – an existing validator class

  • validators (collections.abc.Mapping) –

    a mapping of new validator callables to extend with, whose structure is as in create.

    Note

    Any validator callables with the same name as an existing one will (silently) replace the old validator callable entirely, effectively overriding any validation done in the “parent” validator class.

    If you wish to instead extend the behavior of a parent’s validator callable, delegate and call it directly in the new validator function by retrieving it using OldValidator.VALIDATORS["validation_keyword_name"].

  • version (str) – a version for the new validator class

  • type_checker (jsonschema.TypeChecker) –

    a type checker, used when applying the type keyword.

    If unprovided, the type checker of the extended jsonschema.protocols.Validator will be carried along.

  • format_checker (jsonschema.FormatChecker) –

    a format checker, used when applying the format keyword.

    If unprovided, the format checker of the extended jsonschema.protocols.Validator will be carried along.

Returns:

a new jsonschema.protocols.Validator class extending the one provided

Note

Meta Schemas

The new validator class will have its parent’s meta schema.

If you wish to change or extend the meta schema in the new validator class, modify META_SCHEMA directly on the returned class. Note that no implicit copying is done, so a copy should likely be made before modifying it, in order to not affect the old validator.

jsonschema.validators.validate(instance, schema, cls=None, *args, **kwargs)[source]#

Validate an instance under the given schema.

>>> validate([2, 3, 4], {"maxItems": 2})
Traceback (most recent call last):
    ...
ValidationError: [2, 3, 4] is too long

validate() will first verify that the provided schema is itself valid, since not doing so can lead to less obvious error messages and fail in less obvious or consistent ways.

If you know you have a valid schema already, especially if you intend to validate multiple instances with the same schema, you likely would prefer using the jsonschema.protocols.Validator.validate method directly on a specific validator (e.g. Draft20212Validator.validate).

Parameters:
  • instance – The instance to validate

  • schema – The schema to validate with

  • cls (jsonschema.protocols.Validator) – The class that will be used to validate the instance.

If the cls argument is not provided, two things will happen in accordance with the specification. First, if the schema has a $schema keyword containing a known meta-schema [1] then the proper validator will be used. The specification recommends that all schemas contain $schema properties for this reason. If no $schema property is found, the default validator class is the latest released draft.

Any other provided positional and keyword arguments will be passed on when instantiating the cls.

Raises:

Footnotes

jsonschema.validators.validates(version)[source]#

Register the decorated validator for a version of the specification.

Registered validators and their meta schemas will be considered when parsing $schema keywords’ URIs.

Parameters:

version (str) – An identifier to use as the version’s name

Returns:

a class decorator to decorate the validator with the version

Return type:

collections.abc.Callable

jsonschema.validators.validator_for(schema, default=<unset>)[source]#

Retrieve the validator class appropriate for validating the given schema.

Uses the $schema keyword that should be present in the given schema to look up the appropriate validator class.

Parameters:
  • schema (collections.abc.Mapping or bool) – the schema to look at

  • default

    the default to return if the appropriate validator class cannot be determined.

    If unprovided, the default is to return the latest supported draft.