You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.5 KiB

4 years ago
  1. .. image:: https://img.shields.io/pypi/v/jsonschema.svg
  2. :target: https://pypi.python.org/pypi/jsonschema
  3. .. image:: https://travis-ci.org/Julian/jsonschema.svg?branch=master
  4. :target: https://travis-ci.org/Julian/jsonschema
  5. .. image:: https://img.shields.io/pypi/l/jsonschema.svg
  6. :target: https://pypi.python.org/pypi/jsonschema
  7. ==========
  8. jsonschema
  9. ==========
  10. ``jsonschema`` is an implementation of `JSON Schema <http://json-schema.org>`_
  11. for Python (supporting 2.7+ including Python 3).
  12. .. code-block:: python
  13. >>> from jsonschema import validate
  14. >>> # A sample schema, like what we'd get from json.load()
  15. >>> schema = {
  16. ... "type" : "object",
  17. ... "properties" : {
  18. ... "price" : {"type" : "number"},
  19. ... "name" : {"type" : "string"},
  20. ... },
  21. ... }
  22. >>> # If no exception is raised by validate(), the instance is valid.
  23. >>> validate({"name" : "Eggs", "price" : 34.99}, schema)
  24. >>> validate(
  25. ... {"name" : "Eggs", "price" : "Invalid"}, schema
  26. ... ) # doctest: +IGNORE_EXCEPTION_DETAIL
  27. Traceback (most recent call last):
  28. ...
  29. ValidationError: 'Invalid' is not of type 'number'
  30. It can also be used from console:
  31. .. code-block:: bash
  32. $ jsonschema -i sample.json sample.schema
  33. Features
  34. --------
  35. * Full support for
  36. `Draft 3 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft3Validator>`_
  37. **and** `Draft 4 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft4Validator>`_
  38. of the schema.
  39. * `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.IValidator.iter_errors>`_
  40. that can iteratively report *all* validation errors.
  41. * Small and extensible
  42. * `Programmatic querying <https://python-jsonschema.readthedocs.io/en/latest/errors/#module-jsonschema>`_
  43. of which properties or items failed validation.
  44. Release Notes
  45. -------------
  46. Version 2.5.0 is mainly a performance release. The interface for `RefResolver`
  47. was extended to add methods that improve performance on CPython.
  48. Support for custom `RefResolver` objects with the legacy interface should *not*
  49. be affected. If you notice something amiss please file an issue ticket.
  50. Running the Test Suite
  51. ----------------------
  52. If you have ``tox`` installed (perhaps via ``pip install tox`` or your
  53. package manager), running``tox`` in the directory of your source checkout will
  54. run ``jsonschema``'s test suite on all of the versions of Python ``jsonschema``
  55. supports. Note that you'll need to have all of those versions installed in
  56. order to run the tests on each of them, otherwise ``tox`` will skip (and fail)
  57. the tests on that version.
  58. Of course you're also free to just run the tests on a single version with your
  59. favorite test runner. The tests live in the ``jsonschema.tests`` package.
  60. Community
  61. ---------
  62. There's a `mailing list <https://groups.google.com/forum/#!forum/jsonschema>`_
  63. for this implementation on Google Groups.
  64. Please join, and feel free to send questions there.
  65. Contributing
  66. ------------
  67. I'm Julian Berman.
  68. ``jsonschema`` is on `GitHub <http://github.com/Julian/jsonschema>`_.
  69. Get in touch, via GitHub or otherwise, if you've got something to contribute,
  70. it'd be most welcome!
  71. You can also generally find me on Freenode (nick: ``tos9``) in various
  72. channels, including ``#python``.
  73. If you feel overwhelmingly grateful, you can woo me with beer money on
  74. `Gittip <https://www.gittip.com/Julian/>`_ or via Google Wallet with the email
  75. in my GitHub profile.