🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

jsonschema

Package Overview
Dependencies
Maintainers
0
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonschema - pypi Package Compare versions

Comparing version
4.21.1
to
4.22.0
+2
jsonschema-4.22.0.dist-info/entry_points.txt
[console_scripts]
jsonschema = jsonschema.cli:main
Copyright (c) 2013 Julian Berman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Metadata-Version: 2.3
Name: jsonschema
Version: 4.22.0
Summary: An implementation of JSON Schema validation for Python
Project-URL: Homepage, https://github.com/python-jsonschema/jsonschema
Project-URL: Documentation, https://python-jsonschema.readthedocs.io/
Project-URL: Issues, https://github.com/python-jsonschema/jsonschema/issues/
Project-URL: Funding, https://github.com/sponsors/Julian
Project-URL: Tidelift, https://tidelift.com/subscription/pkg/pypi-jsonschema?utm_source=pypi-jsonschema&utm_medium=referral&utm_campaign=pypi-link
Project-URL: Changelog, https://github.com/python-jsonschema/jsonschema/blob/main/CHANGELOG.rst
Project-URL: Source, https://github.com/python-jsonschema/jsonschema
Author-email: Julian Berman <Julian+jsonschema@GrayVines.com>
License: MIT
License-File: COPYING
Keywords: data validation,json,json schema,jsonschema,validation
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: File Formats :: JSON
Classifier: Topic :: File Formats :: JSON :: JSON Schema
Requires-Python: >=3.8
Requires-Dist: attrs>=22.2.0
Requires-Dist: importlib-resources>=1.4.0; python_version < '3.9'
Requires-Dist: jsonschema-specifications>=2023.03.6
Requires-Dist: pkgutil-resolve-name>=1.3.10; python_version < '3.9'
Requires-Dist: referencing>=0.28.4
Requires-Dist: rpds-py>=0.7.1
Provides-Extra: format
Requires-Dist: fqdn; extra == 'format'
Requires-Dist: idna; extra == 'format'
Requires-Dist: isoduration; extra == 'format'
Requires-Dist: jsonpointer>1.13; extra == 'format'
Requires-Dist: rfc3339-validator; extra == 'format'
Requires-Dist: rfc3987; extra == 'format'
Requires-Dist: uri-template; extra == 'format'
Requires-Dist: webcolors>=1.11; extra == 'format'
Provides-Extra: format-nongpl
Requires-Dist: fqdn; extra == 'format-nongpl'
Requires-Dist: idna; extra == 'format-nongpl'
Requires-Dist: isoduration; extra == 'format-nongpl'
Requires-Dist: jsonpointer>1.13; extra == 'format-nongpl'
Requires-Dist: rfc3339-validator; extra == 'format-nongpl'
Requires-Dist: rfc3986-validator>0.1.0; extra == 'format-nongpl'
Requires-Dist: uri-template; extra == 'format-nongpl'
Requires-Dist: webcolors>=1.11; extra == 'format-nongpl'
Description-Content-Type: text/x-rst
==========
jsonschema
==========
|PyPI| |Pythons| |CI| |ReadTheDocs| |Precommit| |Zenodo|
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema.svg
:alt: PyPI version
:target: https://pypi.org/project/jsonschema/
.. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema.svg
:alt: Supported Python versions
:target: https://pypi.org/project/jsonschema/
.. |CI| image:: https://github.com/python-jsonschema/jsonschema/workflows/CI/badge.svg
:alt: Build status
:target: https://github.com/python-jsonschema/jsonschema/actions?query=workflow%3ACI
.. |ReadTheDocs| image:: https://readthedocs.org/projects/python-jsonschema/badge/?version=stable&style=flat
:alt: ReadTheDocs status
:target: https://python-jsonschema.readthedocs.io/en/stable/
.. |Precommit| image:: https://results.pre-commit.ci/badge/github/python-jsonschema/jsonschema/main.svg
:alt: pre-commit.ci status
:target: https://results.pre-commit.ci/latest/github/python-jsonschema/jsonschema/main
.. |Zenodo| image:: https://zenodo.org/badge/3072629.svg
:alt: Zenodo DOI
:target: https://zenodo.org/badge/latestdoi/3072629
``jsonschema`` is an implementation of the `JSON Schema <https://json-schema.org>`_ specification for Python.
.. code:: python
>>> from jsonschema import validate
>>> # A sample schema, like what we'd get from json.load()
>>> schema = {
... "type" : "object",
... "properties" : {
... "price" : {"type" : "number"},
... "name" : {"type" : "string"},
... },
... }
>>> # If no exception is raised by validate(), the instance is valid.
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)
>>> validate(
... instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema,
... ) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValidationError: 'Invalid' is not of type 'number'
It can also be used from the command line by installing `check-jsonschema <https://github.com/python-jsonschema/check-jsonschema>`_.
Features
--------
* Full support for `Draft 2020-12 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft202012Validator>`_, `Draft 2019-09 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft201909Validator>`_, `Draft 7 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft7Validator>`_, `Draft 6 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft6Validator>`_, `Draft 4 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft4Validator>`_ and `Draft 3 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft3Validator>`_
* `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/protocols/#jsonschema.protocols.Validator.iter_errors>`_ that can iteratively report *all* validation errors.
* `Programmatic querying <https://python-jsonschema.readthedocs.io/en/latest/errors/>`_ of which properties or items failed validation.
Installation
------------
``jsonschema`` is available on `PyPI <https://pypi.org/project/jsonschema/>`_. You can install using `pip <https://pip.pypa.io/en/stable/>`_:
.. code:: bash
$ pip install jsonschema
Extras
======
Two extras are available when installing the package, both currently related to ``format`` validation:
* ``format``
* ``format-nongpl``
They can be used when installing in order to include additional dependencies, e.g.:
.. code:: bash
$ pip install jsonschema'[format]'
Be aware that the mere presence of these dependencies – or even the specification of ``format`` checks in a schema – do *not* activate format checks (as per the specification).
Please read the `format validation documentation <https://python-jsonschema.readthedocs.io/en/latest/validate/#validating-formats>`_ for further details.
About
-----
I'm Julian Berman.
``jsonschema`` is on `GitHub <https://github.com/python-jsonschema/jsonschema>`_.
Get in touch, via GitHub or otherwise, if you've got something to contribute, it'd be most welcome!
You can also generally find me on Libera (nick: ``Julian``) in various channels, including ``#python``.
If you feel overwhelmingly grateful, you can also `sponsor me <https://github.com/sponsors/Julian/>`_.
And for companies who appreciate ``jsonschema`` and its continued support and growth, ``jsonschema`` is also now supportable via `TideLift <https://tidelift.com/subscription/pkg/pypi-jsonschema?utm_source=pypi-jsonschema&utm_medium=referral&utm_campaign=readme>`_.
Release Information
-------------------
v4.22.0
=======
* Improve ``best_match`` (and thereby error messages from ``jsonschema.validate``) in cases where there are multiple *sibling* errors from applying ``anyOf`` / ``allOf`` -- i.e. when multiple elements of a JSON array have errors, we now do prefer showing errors from earlier elements rather than simply showing an error for the full array (#1250).
* (Micro-)optimize equality checks when comparing for JSON Schema equality by first checking for object identity, as ``==`` would.
jsonschema/__init__.py,sha256=LkPwscySlJ9lTOp7ZB1M7jQ8mbG7-bYG41iBwbZ-o9s,3941
jsonschema/__main__.py,sha256=iLsZf2upUB3ilBKTlMnyK-HHt2Cnnfkwwxi_c6gLvSA,115
jsonschema/_format.py,sha256=CUs9_8jlbg-GTb6xWaH5AdxGOFm9VWyCvSCq5KNIQBA,14714
jsonschema/_keywords.py,sha256=r8_DrqAfn6QLwQnmXEggveiSU-UaIL2p2nuPINelfFc,14949
jsonschema/_legacy_keywords.py,sha256=2tWuwRPWbYS7EAl8wBIC_rabGuv1J4dfYLqNEPpShhA,15191
jsonschema/_types.py,sha256=HQ5QD_oL85zF1FSW2v-5rvfYF0967HJdxSR88kzw2mY,5367
jsonschema/_typing.py,sha256=NZhPhkBOn9INYZk8G69rDeuRamztgXCMLh10z9cfT6g,610
jsonschema/_utils.py,sha256=ODga3vrJ6K2wMGxerpgn4ipc9q7ZSqBsvwKU4embLEE,10642
jsonschema/cli.py,sha256=SGy9JPg02mgXhNxugU8iXhYNivfSjBhKTNAgV90ty-M,8551
jsonschema/exceptions.py,sha256=ngFaUUZMtyX9nTb94VfTnWOk4JdNsZiejBAvEezG688,14331
jsonschema/protocols.py,sha256=7mpZxO1gfRNMCGXwldwsSN3nEugVfIVyKZ_HZgN1vSw,7174
jsonschema/validators.py,sha256=H31FwHdyB7LP5eunxdBrZ9E57hpvozfnRlZaOYy45jU,47045
jsonschema/benchmarks/__init__.py,sha256=A0sQrxDBVHSyQ-8ru3L11hMXf3q9gVuB9x_YgHb4R9M,70
jsonschema/benchmarks/const_vs_enum.py,sha256=DVFi3WDqBalZFOibnjpX1uTSr3Rxa2cPgFcowd7Ukrs,830
jsonschema/benchmarks/contains.py,sha256=gexQoUrCOwECofbt19BeosQZ7WFL6PDdkX49DWwBlOg,786
jsonschema/benchmarks/issue232.py,sha256=3LLYLIlBGQnVuyyo2iAv-xky5P6PRFHANx4-zIIQOoE,521
jsonschema/benchmarks/json_schema_test_suite.py,sha256=PvfabpUYcF4_7csYDTcTauED8rnFEGYbdY5RqTXD08s,320
jsonschema/benchmarks/nested_schemas.py,sha256=mo07dx-CIgmSOI62CNs4g5xu1FzHklLBpkQoDxWYcKs,1892
jsonschema/benchmarks/subcomponents.py,sha256=fEyiMzsWeK2pd7DEGCuuY-vzGunwhHczRBWEnBRLKIo,1113
jsonschema/benchmarks/unused_registry.py,sha256=hwRwONc9cefPtYzkoX_TYRO3GyUojriv0-YQaK3vnj0,940
jsonschema/benchmarks/useless_applicator_schemas.py,sha256=EVm5-EtOEFoLP_Vt2j4SrCwlx05NhPqNuZQ6LIMP1Dc,3342
jsonschema/benchmarks/useless_keywords.py,sha256=bj_zKr1oVctFlqyZaObCsYTgFjiiNgPzC0hr1Y868mE,867
jsonschema/benchmarks/validator_creation.py,sha256=UkUQlLAnussnr_KdCIdad6xx2pXxQLmYtsXoiirKeWQ,285
jsonschema/benchmarks/issue232/issue.json,sha256=eaPOZjMRu5u8RpKrsA9uk7ucPZS5tkKG4D_hkOTQ3Hk,117105
jsonschema/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
jsonschema/tests/_suite.py,sha256=QAfBj34zMbJQ5_JJ2ogpiTlw9hQ6Is43dvo_bpS0EdM,8156
jsonschema/tests/fuzz_validate.py,sha256=fUA7yTJIihaCwJplkUehZeyB84HcXEcqtY5oPJXIO7I,1114
jsonschema/tests/test_cli.py,sha256=uFMu2YbIfbSDCnykhLL4-VR3-jg1tvQLJn2Bliwp_Bw,28587
jsonschema/tests/test_deprecations.py,sha256=9VxOCfWzMG1Tg4OD8riU_Znd6HDOQZkepzVgxsdUdU8,15760
jsonschema/tests/test_exceptions.py,sha256=biVA6UqwhYutjSxpTr1mHcsfGjXCjUSRWbrdKC_6O38,21994
jsonschema/tests/test_format.py,sha256=eVm5SMaWF2lOPO28bPAwNvkiQvHCQKy-MnuAgEchfEc,3188
jsonschema/tests/test_jsonschema_test_suite.py,sha256=a2saPs2Cwwg0sdRdu-uJ8goSXLbqrS-pC48QJy0K4DE,8674
jsonschema/tests/test_types.py,sha256=cF51KTDmdsx06MrIc4fXKt0X9fIsVgw5uhT8CamVa8U,6977
jsonschema/tests/test_utils.py,sha256=sao74o1PyYMxBfqweokQN48CFSS6yhJk5FkCfMJ5PsI,4163
jsonschema/tests/test_validators.py,sha256=eiaigsZMzHYYsniQ1UPygaS56a1d-_7-9NC4wVXAhzs,87975
jsonschema-4.22.0.dist-info/METADATA,sha256=jhijmeEY8FsE_tiJzZ1RBvEtO15WxwLsytzkiM6kr3Y,8205
jsonschema-4.22.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
jsonschema-4.22.0.dist-info/entry_points.txt,sha256=vO7rX4Fs_xIVJy2pnAtKgTSxfpnozAVQ0DjCmpMxnWE,51
jsonschema-4.22.0.dist-info/licenses/COPYING,sha256=T5KgFaE8TRoEC-8BiqE0MLTxvHO0Gxa7hGw0Z2bedDk,1057
jsonschema-4.22.0.dist-info/RECORD,,
Wheel-Version: 1.0
Generator: hatchling 1.24.2
Root-Is-Purelib: true
Tag: py3-none-any
"""
A benchmark for comparing equivalent validation of `const` and `enum`.
"""
from pyperf import Runner
from jsonschema import Draft202012Validator
value = [37] * 100
const_schema = {"const": list(value)}
enum_schema = {"enum": [list(value)]}
valid = list(value)
invalid = [*valid, 73]
const = Draft202012Validator(const_schema)
enum = Draft202012Validator(enum_schema)
assert const.is_valid(valid)
assert enum.is_valid(valid)
assert not const.is_valid(invalid)
assert not enum.is_valid(invalid)
if __name__ == "__main__":
runner = Runner()
runner.bench_func("const valid", lambda: const.is_valid(valid))
runner.bench_func("const invalid", lambda: const.is_valid(invalid))
runner.bench_func("enum valid", lambda: enum.is_valid(valid))
runner.bench_func("enum invalid", lambda: enum.is_valid(invalid))
"""
A benchmark for validation of applicators containing lots of useless schemas.
Signals a small possible optimization to remove all such schemas ahead of time.
"""
from pyperf import Runner
from jsonschema import Draft202012Validator as Validator
NUM_USELESS = 100000
subschema = {"const": 37}
valid = 37
invalid = 12
baseline = Validator(subschema)
# These should be indistinguishable from just `subschema`
by_name = {
"single subschema": {
"anyOf": Validator({"anyOf": [subschema]}),
"allOf": Validator({"allOf": [subschema]}),
"oneOf": Validator({"oneOf": [subschema]}),
},
"redundant subschemas": {
"anyOf": Validator({"anyOf": [subschema] * NUM_USELESS}),
"allOf": Validator({"allOf": [subschema] * NUM_USELESS}),
},
"useless successful subschemas (beginning)": {
"anyOf": Validator({"anyOf": [subschema, *[True] * NUM_USELESS]}),
"allOf": Validator({"allOf": [subschema, *[True] * NUM_USELESS]}),
},
"useless successful subschemas (middle)": {
"anyOf": Validator(
{
"anyOf": [
*[True] * (NUM_USELESS // 2),
subschema,
*[True] * (NUM_USELESS // 2),
],
},
),
"allOf": Validator(
{
"allOf": [
*[True] * (NUM_USELESS // 2),
subschema,
*[True] * (NUM_USELESS // 2),
],
},
),
},
"useless successful subschemas (end)": {
"anyOf": Validator({"anyOf": [*[True] * NUM_USELESS, subschema]}),
"allOf": Validator({"allOf": [*[True] * NUM_USELESS, subschema]}),
},
"useless failing subschemas (beginning)": {
"anyOf": Validator({"anyOf": [subschema, *[False] * NUM_USELESS]}),
"oneOf": Validator({"oneOf": [subschema, *[False] * NUM_USELESS]}),
},
"useless failing subschemas (middle)": {
"anyOf": Validator(
{
"anyOf": [
*[False] * (NUM_USELESS // 2),
subschema,
*[False] * (NUM_USELESS // 2),
],
},
),
"oneOf": Validator(
{
"oneOf": [
*[False] * (NUM_USELESS // 2),
subschema,
*[False] * (NUM_USELESS // 2),
],
},
),
},
"useless failing subschemas (end)": {
"anyOf": Validator({"anyOf": [*[False] * NUM_USELESS, subschema]}),
"oneOf": Validator({"oneOf": [*[False] * NUM_USELESS, subschema]}),
},
}
if __name__ == "__main__":
runner = Runner()
runner.bench_func("baseline valid", lambda: baseline.is_valid(valid))
runner.bench_func("baseline invalid", lambda: baseline.is_valid(invalid))
for group, applicators in by_name.items():
for applicator, validator in applicators.items():
runner.bench_func(
f"{group}: {applicator} valid",
lambda validator=validator: validator.is_valid(valid),
)
runner.bench_func(
f"{group}: {applicator} invalid",
lambda validator=validator: validator.is_valid(invalid),
)
"""
A benchmark for validation of schemas containing lots of useless keywords.
Checks we filter them out once, ahead of time.
"""
from pyperf import Runner
from jsonschema import Draft202012Validator
NUM_USELESS = 100000
schema = dict(
[
("not", {"const": 42}),
*((str(i), i) for i in range(NUM_USELESS)),
("type", "integer"),
*((str(i), i) for i in range(NUM_USELESS, NUM_USELESS)),
("minimum", 37),
],
)
validator = Draft202012Validator(schema)
valid = 3737
invalid = 12
if __name__ == "__main__":
runner = Runner()
runner.bench_func("beginning of schema", lambda: validator.is_valid(42))
runner.bench_func("middle of schema", lambda: validator.is_valid("foo"))
runner.bench_func("end of schema", lambda: validator.is_valid(12))
runner.bench_func("valid", lambda: validator.is_valid(3737))
+4
-0

@@ -43,2 +43,3 @@ from __future__ import annotations

limit which formats will be used during validation.
"""

@@ -79,2 +80,3 @@

resulting validation error.
"""

@@ -132,2 +134,3 @@

if the instance does not conform to ``format``
"""

@@ -163,2 +166,3 @@ if format not in self.checkers:

bool: whether it conformed
"""

@@ -165,0 +169,0 @@ try:

@@ -79,2 +79,3 @@ from __future__ import annotations

The initial mapping of types to their checking functions.
"""

@@ -109,2 +110,3 @@

if ``type`` is unknown to this object.
"""

@@ -134,2 +136,3 @@ try:

type and false otherwise.
"""

@@ -147,2 +150,3 @@ return self.redefine_many({type: fn})

A dictionary mapping types to their checking functions.
"""

@@ -167,2 +171,3 @@ type_checkers = self._type_checkers.update(definitions)

if any given type is unknown to this object
"""

@@ -169,0 +174,0 @@ type_checkers = self._type_checkers

@@ -62,2 +62,3 @@ from collections.abc import Mapping, MutableMapping, Sequence

The indices to format.
"""

@@ -134,2 +135,4 @@ if not indices:

"""
if one is two:
return True
if isinstance(one, str) or isinstance(two, str):

@@ -136,0 +139,0 @@ return one == two

+9
-6

@@ -393,2 +393,3 @@ """

"strong"
"""

@@ -398,8 +399,9 @@

validator = error.validator
return (
-len(error.path),
validator not in weak,
validator in strong,
not error._matches_type(),
)
return ( # prefer errors which are ...
-len(error.path), # 'deeper' and thereby more specific
error.path, # earlier (for sibling errors)
validator not in weak, # for a non-low-priority keyword
validator in strong, # for a high priority keyword
not error._matches_type(), # at least match the instance's type
) # otherwise we'll treat them the same

@@ -458,2 +460,3 @@ return relevance

set of inputs from version to version if better heuristics are added.
"""

@@ -460,0 +463,0 @@ errors = iter(errors)

@@ -89,2 +89,3 @@ """

their public API.
"""

@@ -133,2 +134,3 @@

if the schema is invalid
"""

@@ -159,2 +161,3 @@

if ``type`` is not a known type
"""

@@ -173,2 +176,3 @@

False
"""

@@ -212,2 +216,3 @@

ValidationError: [2, 3, 4] is too long
"""

@@ -214,0 +219,0 @@

@@ -22,3 +22,3 @@ """

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping
from collections.abc import Iterable, Mapping, Sequence

@@ -166,2 +166,3 @@ import pyperf

comment: str | None = None
specification: Sequence[dict[str, str]] = ()

@@ -168,0 +169,0 @@ @classmethod

@@ -11,4 +11,8 @@ from unittest import TestCase

errors = list(_LATEST_VERSION(schema).iter_errors(instance))
msg = f"No errors found for {instance} under {schema!r}!"
self.assertTrue(errors, msg=msg)
best = exceptions.best_match(iter(errors))
reversed_best = exceptions.best_match(reversed(errors))
self.assertEqual(

@@ -100,2 +104,31 @@ best._contents(),

def test_anyOf_traversal_for_single_sibling_errors(self):
"""
We *do* traverse anyOf with a single subschema that fails multiple
times (e.g. on multiple items).
"""
schema = {
"anyOf": [
{"items": {"const": 37}},
],
}
best = self.best_match_of(instance=[12, 12], schema=schema)
self.assertEqual(best.validator, "const")
def test_anyOf_traversal_for_non_type_matching_sibling_errors(self):
"""
We *do* traverse anyOf with multiple subschemas when one does not type
match.
"""
schema = {
"anyOf": [
{"type": "object"},
{"items": {"const": 37}},
],
}
best = self.best_match_of(instance=[12, 12], schema=schema)
self.assertEqual(best.validator, "const")
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):

@@ -154,2 +187,31 @@ """

def test_oneOf_traversal_for_single_sibling_errors(self):
"""
We *do* traverse oneOf with a single subschema that fails multiple
times (e.g. on multiple items).
"""
schema = {
"oneOf": [
{"items": {"const": 37}},
],
}
best = self.best_match_of(instance=[12, 12], schema=schema)
self.assertEqual(best.validator, "const")
def test_oneOf_traversal_for_non_type_matching_sibling_errors(self):
"""
We *do* traverse oneOf with multiple subschemas when one does not type
match.
"""
schema = {
"oneOf": [
{"type": "object"},
{"items": {"const": 37}},
],
}
best = self.best_match_of(instance=[12, 12], schema=schema)
self.assertEqual(best.validator, "const")
def test_if_the_most_relevant_error_is_allOf_it_is_traversed(self):

@@ -156,0 +218,0 @@ """

@@ -0,1 +1,2 @@

from math import nan
from unittest import TestCase

@@ -10,3 +11,6 @@

def test_nan(self):
self.assertTrue(equal(nan, nan))
class TestDictEqual(TestCase):

@@ -18,2 +22,7 @@ def test_equal_dictionaries(self):

def test_equal_dictionaries_with_nan(self):
dict_1 = {"a": nan, "c": "d"}
dict_2 = {"c": "d", "a": nan}
self.assertTrue(equal(dict_1, dict_2))
def test_missing_key(self):

@@ -75,2 +84,7 @@ dict_1 = {"a": "b", "c": "d"}

def test_equal_lists_with_nan(self):
list_1 = ["a", nan, "c"]
list_2 = ["a", nan, "c"]
self.assertTrue(equal(list_1, list_2))
def test_unsorted_lists(self):

@@ -77,0 +91,0 @@ list_1 = ["a", "b", "c"]

@@ -98,2 +98,3 @@ """

a class decorator to decorate the validator with the version
"""

@@ -213,2 +214,3 @@

a new `jsonschema.protocols.Validator` class
"""

@@ -233,2 +235,3 @@ # preemptively don't shadow the `Validator.format_checker` local

_APPLICABLE_VALIDATORS = applicable_validators
_validators = field(init=False, repr=False, eq=False)

@@ -291,2 +294,11 @@ schema: referencing.jsonschema.Schema = field(repr=reprlib.repr)

if self.schema is True or self.schema is False:
self._validators = []
else:
self._validators = [
(self.VALIDATORS[k], k, v)
for k, v in applicable_validators(self.schema)
if k in self.VALIDATORS
]
# REMOVEME: Legacy ref resolution state management.

@@ -354,4 +366,9 @@ push_scope = getattr(self._ref_resolver, "push_scope", None)

)
validators = [
(self.VALIDATORS[k], k, v)
for k, v in applicable_validators(_schema)
if k in self.VALIDATORS
]
else:
_schema = self.schema
_schema, validators = self.schema, self._validators

@@ -370,7 +387,3 @@ if _schema is True:

for k, v in applicable_validators(_schema):
validator = self.VALIDATORS.get(k)
if validator is None:
continue
for validator, k, v in validators:
errors = validator(self, v, instance, _schema) or ()

@@ -575,2 +588,3 @@ for error in errors:

old validator.
"""

@@ -902,2 +916,3 @@ all_validators = dict(validator.VALIDATORS)

``RefResolver`` has been deprecated in favor of `referencing`.
"""

@@ -972,2 +987,3 @@

`_RefResolver`
"""

@@ -1052,2 +1068,3 @@ return cls(base_uri=id_of(schema) or "", referrer=schema, *args, **kwargs) # noqa: B026, E501

The reference to resolve
"""

@@ -1116,3 +1133,3 @@ url, resolved = self.resolve(ref)

document = self.resolve_remote(url)
except Exception as exc: # noqa: BLE001
except Exception as exc:
raise exceptions._RefResolutionError(exc) from exc

@@ -1135,2 +1152,3 @@

a URI fragment to resolve within it
"""

@@ -1205,2 +1223,3 @@ fragment = fragment.lstrip("/")

.. _requests: https://pypi.org/project/requests/
"""

@@ -1317,2 +1336,3 @@ try:

`jsonschema.validators.validates`
"""

@@ -1329,3 +1349,6 @@ if cls is None:

def validator_for(schema, default=_UNSET) -> Validator:
def validator_for(
schema,
default: Validator | _utils.Unset = _UNSET,
) -> type[Validator]:
"""

@@ -1332,0 +1355,0 @@ Retrieve the validator class appropriate for validating the given schema.

[console_scripts]
jsonschema = jsonschema.cli:main
Copyright (c) 2013 Julian Berman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Metadata-Version: 2.1
Name: jsonschema
Version: 4.21.1
Summary: An implementation of JSON Schema validation for Python
Project-URL: Homepage, https://github.com/python-jsonschema/jsonschema
Project-URL: Documentation, https://python-jsonschema.readthedocs.io/
Project-URL: Issues, https://github.com/python-jsonschema/jsonschema/issues/
Project-URL: Funding, https://github.com/sponsors/Julian
Project-URL: Tidelift, https://tidelift.com/subscription/pkg/pypi-jsonschema?utm_source=pypi-jsonschema&utm_medium=referral&utm_campaign=pypi-link
Project-URL: Changelog, https://github.com/python-jsonschema/jsonschema/blob/main/CHANGELOG.rst
Project-URL: Source, https://github.com/python-jsonschema/jsonschema
Author: Julian Berman
Author-email: Julian+jsonschema@GrayVines.com
License: MIT
License-File: COPYING
Keywords: data validation,json,json schema,jsonschema,validation
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: File Formats :: JSON
Classifier: Topic :: File Formats :: JSON :: JSON Schema
Requires-Python: >=3.8
Requires-Dist: attrs>=22.2.0
Requires-Dist: importlib-resources>=1.4.0; python_version < '3.9'
Requires-Dist: jsonschema-specifications>=2023.03.6
Requires-Dist: pkgutil-resolve-name>=1.3.10; python_version < '3.9'
Requires-Dist: referencing>=0.28.4
Requires-Dist: rpds-py>=0.7.1
Provides-Extra: format
Requires-Dist: fqdn; extra == 'format'
Requires-Dist: idna; extra == 'format'
Requires-Dist: isoduration; extra == 'format'
Requires-Dist: jsonpointer>1.13; extra == 'format'
Requires-Dist: rfc3339-validator; extra == 'format'
Requires-Dist: rfc3987; extra == 'format'
Requires-Dist: uri-template; extra == 'format'
Requires-Dist: webcolors>=1.11; extra == 'format'
Provides-Extra: format-nongpl
Requires-Dist: fqdn; extra == 'format-nongpl'
Requires-Dist: idna; extra == 'format-nongpl'
Requires-Dist: isoduration; extra == 'format-nongpl'
Requires-Dist: jsonpointer>1.13; extra == 'format-nongpl'
Requires-Dist: rfc3339-validator; extra == 'format-nongpl'
Requires-Dist: rfc3986-validator>0.1.0; extra == 'format-nongpl'
Requires-Dist: uri-template; extra == 'format-nongpl'
Requires-Dist: webcolors>=1.11; extra == 'format-nongpl'
Description-Content-Type: text/x-rst
==========
jsonschema
==========
|PyPI| |Pythons| |CI| |ReadTheDocs| |Precommit| |Zenodo|
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema.svg
:alt: PyPI version
:target: https://pypi.org/project/jsonschema/
.. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema.svg
:alt: Supported Python versions
:target: https://pypi.org/project/jsonschema/
.. |CI| image:: https://github.com/python-jsonschema/jsonschema/workflows/CI/badge.svg
:alt: Build status
:target: https://github.com/python-jsonschema/jsonschema/actions?query=workflow%3ACI
.. |ReadTheDocs| image:: https://readthedocs.org/projects/python-jsonschema/badge/?version=stable&style=flat
:alt: ReadTheDocs status
:target: https://python-jsonschema.readthedocs.io/en/stable/
.. |Precommit| image:: https://results.pre-commit.ci/badge/github/python-jsonschema/jsonschema/main.svg
:alt: pre-commit.ci status
:target: https://results.pre-commit.ci/latest/github/python-jsonschema/jsonschema/main
.. |Zenodo| image:: https://zenodo.org/badge/3072629.svg
:alt: Zenodo DOI
:target: https://zenodo.org/badge/latestdoi/3072629
``jsonschema`` is an implementation of the `JSON Schema <https://json-schema.org>`_ specification for Python.
.. code:: python
>>> from jsonschema import validate
>>> # A sample schema, like what we'd get from json.load()
>>> schema = {
... "type" : "object",
... "properties" : {
... "price" : {"type" : "number"},
... "name" : {"type" : "string"},
... },
... }
>>> # If no exception is raised by validate(), the instance is valid.
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)
>>> validate(
... instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema,
... ) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValidationError: 'Invalid' is not of type 'number'
It can also be used from the command line by installing `check-jsonschema <https://github.com/python-jsonschema/check-jsonschema>`_.
Features
--------
* Full support for `Draft 2020-12 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft202012Validator>`_, `Draft 2019-09 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft201909Validator>`_, `Draft 7 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft7Validator>`_, `Draft 6 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft6Validator>`_, `Draft 4 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft4Validator>`_ and `Draft 3 <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/validators/#jsonschema.validators.Draft3Validator>`_
* `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/api/jsonschema/protocols/#jsonschema.protocols.Validator.iter_errors>`_ that can iteratively report *all* validation errors.
* `Programmatic querying <https://python-jsonschema.readthedocs.io/en/latest/errors/>`_ of which properties or items failed validation.
Installation
------------
``jsonschema`` is available on `PyPI <https://pypi.org/project/jsonschema/>`_. You can install using `pip <https://pip.pypa.io/en/stable/>`_:
.. code:: bash
$ pip install jsonschema
Extras
======
Two extras are available when installing the package, both currently related to ``format`` validation:
* ``format``
* ``format-nongpl``
They can be used when installing in order to include additional dependencies, e.g.:
.. code:: bash
$ pip install jsonschema'[format]'
Be aware that the mere presence of these dependencies – or even the specification of ``format`` checks in a schema – do *not* activate format checks (as per the specification).
Please read the `format validation documentation <https://python-jsonschema.readthedocs.io/en/latest/validate/#validating-formats>`_ for further details.
About
-----
I'm Julian Berman.
``jsonschema`` is on `GitHub <https://github.com/python-jsonschema/jsonschema>`_.
Get in touch, via GitHub or otherwise, if you've got something to contribute, it'd be most welcome!
You can also generally find me on Libera (nick: ``Julian``) in various channels, including ``#python``.
If you feel overwhelmingly grateful, you can also `sponsor me <https://github.com/sponsors/Julian/>`_.
And for companies who appreciate ``jsonschema`` and its continued support and growth, ``jsonschema`` is also now supportable via `TideLift <https://tidelift.com/subscription/pkg/pypi-jsonschema?utm_source=pypi-jsonschema&utm_medium=referral&utm_campaign=readme>`_.
Release Information
-------------------
v4.21.1
=======
* Slightly speed up the ``contains`` keyword by removing some unnecessary validator (re-)creation.
jsonschema/__init__.py,sha256=LkPwscySlJ9lTOp7ZB1M7jQ8mbG7-bYG41iBwbZ-o9s,3941
jsonschema/__main__.py,sha256=iLsZf2upUB3ilBKTlMnyK-HHt2Cnnfkwwxi_c6gLvSA,115
jsonschema/_format.py,sha256=zU9Bg18dn1u9f43ORXo6_zpcR92Tm1dz0UlYXjzjbgU,14710
jsonschema/_keywords.py,sha256=r8_DrqAfn6QLwQnmXEggveiSU-UaIL2p2nuPINelfFc,14949
jsonschema/_legacy_keywords.py,sha256=2tWuwRPWbYS7EAl8wBIC_rabGuv1J4dfYLqNEPpShhA,15191
jsonschema/_types.py,sha256=WDFT49X-gQd4w5IbzpjZyhVdOtjC4swQ4uHaPmH5svw,5362
jsonschema/_typing.py,sha256=NZhPhkBOn9INYZk8G69rDeuRamztgXCMLh10z9cfT6g,610
jsonschema/_utils.py,sha256=z8rU2vVCYRi3XUV8bXVTw9RzgMkC74C9olPfaFh8-18,10602
jsonschema/cli.py,sha256=SGy9JPg02mgXhNxugU8iXhYNivfSjBhKTNAgV90ty-M,8551
jsonschema/exceptions.py,sha256=4g6a74jSb_jnSyzmAOhxwPh3MYiQHFyrJlV8s7FFN6I,13977
jsonschema/protocols.py,sha256=XXRIlsboM5lc0mxeMSUCQmrqtcGzSM5TuwfIKBB4RuQ,7169
jsonschema/validators.py,sha256=yT2oAenK3cRyhcTeHObvfCm0AWmPXhUC_idor_IIMwQ,46510
jsonschema/benchmarks/__init__.py,sha256=A0sQrxDBVHSyQ-8ru3L11hMXf3q9gVuB9x_YgHb4R9M,70
jsonschema/benchmarks/contains.py,sha256=gexQoUrCOwECofbt19BeosQZ7WFL6PDdkX49DWwBlOg,786
jsonschema/benchmarks/issue232.py,sha256=3LLYLIlBGQnVuyyo2iAv-xky5P6PRFHANx4-zIIQOoE,521
jsonschema/benchmarks/json_schema_test_suite.py,sha256=PvfabpUYcF4_7csYDTcTauED8rnFEGYbdY5RqTXD08s,320
jsonschema/benchmarks/nested_schemas.py,sha256=mo07dx-CIgmSOI62CNs4g5xu1FzHklLBpkQoDxWYcKs,1892
jsonschema/benchmarks/subcomponents.py,sha256=fEyiMzsWeK2pd7DEGCuuY-vzGunwhHczRBWEnBRLKIo,1113
jsonschema/benchmarks/unused_registry.py,sha256=hwRwONc9cefPtYzkoX_TYRO3GyUojriv0-YQaK3vnj0,940
jsonschema/benchmarks/validator_creation.py,sha256=UkUQlLAnussnr_KdCIdad6xx2pXxQLmYtsXoiirKeWQ,285
jsonschema/benchmarks/issue232/issue.json,sha256=eaPOZjMRu5u8RpKrsA9uk7ucPZS5tkKG4D_hkOTQ3Hk,117105
jsonschema/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
jsonschema/tests/_suite.py,sha256=rP6N9rGYrfWJCmPfiUbfodfQ0twqUJkk8sblGD7pzek,8097
jsonschema/tests/fuzz_validate.py,sha256=fUA7yTJIihaCwJplkUehZeyB84HcXEcqtY5oPJXIO7I,1114
jsonschema/tests/test_cli.py,sha256=uFMu2YbIfbSDCnykhLL4-VR3-jg1tvQLJn2Bliwp_Bw,28587
jsonschema/tests/test_deprecations.py,sha256=9VxOCfWzMG1Tg4OD8riU_Znd6HDOQZkepzVgxsdUdU8,15760
jsonschema/tests/test_exceptions.py,sha256=26l4I4luUt47m6CXpR2xXoZPcMAWGq7kbavJ1S8UiaU,20112
jsonschema/tests/test_format.py,sha256=eVm5SMaWF2lOPO28bPAwNvkiQvHCQKy-MnuAgEchfEc,3188
jsonschema/tests/test_jsonschema_test_suite.py,sha256=a2saPs2Cwwg0sdRdu-uJ8goSXLbqrS-pC48QJy0K4DE,8674
jsonschema/tests/test_types.py,sha256=cF51KTDmdsx06MrIc4fXKt0X9fIsVgw5uhT8CamVa8U,6977
jsonschema/tests/test_utils.py,sha256=lJRVYyQeZQTUCTU_M3BhlkxPMgjsc8KQCd7U_Qkook8,3749
jsonschema/tests/test_validators.py,sha256=eiaigsZMzHYYsniQ1UPygaS56a1d-_7-9NC4wVXAhzs,87975
jsonschema-4.21.1.dist-info/METADATA,sha256=x2J7cuqnMmopRhlFHCtWMD1nQ3qiUpMqh0yz2cRTPT8,7831
jsonschema-4.21.1.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
jsonschema-4.21.1.dist-info/entry_points.txt,sha256=vO7rX4Fs_xIVJy2pnAtKgTSxfpnozAVQ0DjCmpMxnWE,51
jsonschema-4.21.1.dist-info/licenses/COPYING,sha256=T5KgFaE8TRoEC-8BiqE0MLTxvHO0Gxa7hGw0Z2bedDk,1057
jsonschema-4.21.1.dist-info/RECORD,,
Wheel-Version: 1.0
Generator: hatchling 1.21.0
Root-Is-Purelib: true
Tag: py3-none-any