{ "info": { "author": "Denis Korytkin", "author_email": "dkorytkin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing", "Topic :: Utilities" ], "description": "json_checker\n===============================================================================\n\n.. image:: https://travis-ci.org/DKorytkin/json_checker.svg?branch=master\n :alt: Build\n :target: https://travis-ci.org/DKorytkin/json_checker\n\n.. image:: https://codecov.io/gh/DKorytkin/json_checker/branch/master/graph/badge.svg\n :alt: Cov\n :target: https://codecov.io/gh/DKorytkin/json_checker\n\n.. image:: https://img.shields.io/badge/python-3.6%2C%20%203.7%2C%20%203.8-blue.svg\n :alt: Python versions\n :target: https://pypi.python.org/pypi/json_checker\n\n.. image:: https://img.shields.io/pypi/v/json_checker.svg \n :alt: PyPI\n :target: https://pypi.python.org/pypi/json_checker\n\n.. image:: https://img.shields.io/pypi/dm/json_checker.svg \n :alt: PyPI - Downloads\n :target: https://pypistats.org/packages/json-checker\n\n**json_checker** is a library for validating Python data structures,\nsuch as those obtained from JSON (or something else) to Python data-types.\njson_checker has a parameter (soft=True) that allows you validate all json and\nraise all errors after validation done, it`s very profitable from API testing:\n\n.. code:: python\n\n >>> import requests\n >>>\n >>> from json_checker import Checker\n >>>\n >>>\n >>> def test_api():\n >>> res = requests.get(API_URL).json()\n >>> assert Checker(EXPECTED_RESPONSE, soft=True).validate(res) == res\n\n\nInstallation\n-------------------------------------------------------------------------------\n\n.. code-block:: sh\n\n $ pip install json_checker\n\n\nExample\n----------------------------------------------------------------------------\n\nHere is a quick example to get a feeling of **json_checker**,\nvalidating a list of entries with personal information:\n\n.. code:: python\n\n >>> from json_checker import Checker\n\n >>> current_data = {'first_key': 1, 'second_key': '2'}\n >>> expected_schema = {'first_key': int, 'second_key': str}\n\n\n >>> checker = Checker(expected_schema)\n >>> result = checker.validate(current_data)\n\n\n >>> assert result == current_data\n\n\nIf data is valid, ``Checker.validate`` will return the validated data\n\nIf data is invalid, ``Checker`` will raise ``CheckerError``.\n\n\nHow ``json_checker`` validates data\n-------------------------------------------------------------------------------\n\nTypes\n~~~~~\n\nIf ``Checker(...)`` encounters a type (such as ``int``, ``str``),\nit will check if the corresponding piece of data is an instance of that type,\notherwise it will raise ``CheckerError``.\n\n.. code:: python\n\n >>> from json_checker import Checker\n\n >>> Checker(int).validate(123)\n 123\n\n >>> Checker(int).validate('123')\n Traceback (most recent call last):\n ...\n checker_exceptions.TypeCheckerError:\n current value '123' (str) is not int\n\n\nLists, similar containers\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf ``Checker(...)`` encounters an instance of ``list``, ``tuple``, ``set`` or\n``frozenset``, it will validate contents of corresponding data container\nagainst schemas listed inside that container:\nif param ``soft`` is True validate all data,\nand if have not valid data raise exception after validation\n\n.. code:: python\n\n >>> Checker([int]).validate([1, 1, 0, 1])\n [1, 1, 0, 1]\n\n >>> Checker([str], soft=True).validate((1, 2, 3))\n Traceback (most recent call last):\n ...\n checker_exceptions.CheckerError:\n ListCheckerErrors:\n current value 1 (int) is not str\n current value 2 (int) is not str\n current value 3 (int) is not str\n\n >>> Checker([str]).validate((1, 2, 3))\n Traceback (most recent call last):\n ...\n checker_exceptions.ListCheckerError:\n current value 1 (int) is not str\n\nDictionaries\n~~~~~~~~~~~~\n\nIf ``Checker(...)`` encounters an instance of ``dict``, it will validate data\nkey-value pairs:\n\n.. code:: python\n\n >>> current_dict = {'first_key': 1, 'second_key': '2'}\n >>> checker = Checker({'first_key': int, 'second_key': int})\n >>> checker.validate(current_dict)\n\n Traceback (most recent call last):\n ...\n checker_exceptions.DictCheckerError:\n From key=\"second_key\"\n current value '2' (str) is not int\n\n\nOperators Or, And, OptionalKey\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you needed validate data from some conditions, use And operator\nfor example current data must be int instance and greater than 0 and less 99\ntry it:\n\n.. code:: python\n\n >>> from json_checker import Checker, And\n\n >>> checker = Checker(And(int, lambda x: 0 < x < 99))\n >>> checker.validate(12)\n 12\n\n >>> checker.validate(100)\n Traceback (most recent call last):\n ...\n checker_exceptions.CheckerError:\n Not valid data And(int, ),\n function error\n\n\nIf you need validation not required data value, use Or operator\nfor example current data must be int or None\ntry it:\n\n.. code:: python\n\n >>> from json_checker import Checker, Or\n\n >>> checker = Checker(Or(int, None))\n >>> checker.validate(122)\n 122\n\n >>> checker.validate('666')\n Traceback (most recent call last):\n ...\n checker_exceptions.CheckerError:\n Not valid data Or('int', None),\n current value '666' (str) is not int, current value '666' (str) is not None\n\nIf you need validate no required dict key, use OptionalKey\n\n.. code:: python\n\n >>> from json_checker import Checker, OptionalKey\n\n >>> expected_schema = {'key1': str, OptionalKey('key2'): int}\n >>> Checker(expected_schema).validate({'key1': 'value'})\n {'key1': 'value'}\n\n >>> Checker(expected_schema).validate({'key1': 'value', 'key2': 'value2'})\n Traceback (most recent call last):\n ...\n checker_exceptions.DictCheckerError:\n From key=\"OptionalKey(key2)\"\n current value 'value2' (str) is not int\n\n\nMore logs for debug\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n >>> import logging\n >>> from json_checker import Checker\n\n >>> logging.basicConfig(level=logging.DEBUG)\n\n >>> Checker({'k': str}, soft=True).validate({'k': 1})\n DEBUG:json_checker.app:Checker settings: ignore_extra_keys=False, soft=True\n DEBUG:json_checker.app:DictChecker({'k': } (dict)) start with: {'k': 1}\n DEBUG:json_checker.app:TypeChecker(str) start with: 1\n DEBUG:json_checker.app:TypeChecker(str) error current value 1 (int) is not str\n DEBUG:json_checker.app:DictChecker({'k': } (dict)) error From key=\"k\": current value 1 (int) is not str\n Traceback (most recent call last):\n ...\n CheckerError:\n From key=\"k\": current value 1 (int) is not str\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/DKorytkin/json_checker", "keywords": "Json checker,API testing,requests testing,json schema validation", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "json-checker", "package_url": "https://pypi.org/project/json-checker/", "platform": "linux", "project_url": "https://pypi.org/project/json-checker/", "project_urls": { "Homepage": "https://github.com/DKorytkin/json_checker" }, "release_url": "https://pypi.org/project/json-checker/2.0.0/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Simple schema validation library", "version": "2.0.0" }, "last_serial": 5764409, "releases": { "1.1.5": [ { "comment_text": "", "digests": { "md5": "03aaa72060a3f51bdc87a205bf7dafd1", "sha256": "c670ee165f6376e43865293c33c1e8a7c311cea735885e3f25545c994ad774e8" }, "downloads": -1, "filename": "json_checker-1.1.5.tar.gz", "has_sig": false, "md5_digest": "03aaa72060a3f51bdc87a205bf7dafd1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5786, "upload_time": "2017-10-06T11:31:41", "url": "https://files.pythonhosted.org/packages/fc/c0/8f7e182830c1d24ee4c8e2a583d0bd920fdffcbe7aff44e6566102231b10/json_checker-1.1.5.tar.gz" } ], "1.1.6": [ { "comment_text": "", "digests": { "md5": "6aeb101666c0309470e9b7015b831c30", "sha256": "9c35654196d25382f8dd8db88fa5ea14e78d4c3a554d409bec78d20b2aca5392" }, "downloads": -1, "filename": "json_checker-1.1.6.tar.gz", "has_sig": false, "md5_digest": "6aeb101666c0309470e9b7015b831c30", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5772, "upload_time": "2017-10-09T06:48:45", "url": "https://files.pythonhosted.org/packages/55/f0/38961ff0f803cb52b464fcf82bce8b75cefef72c83508c1870e47d7526d3/json_checker-1.1.6.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "750e637b3930effb9c3600732e73d59b", "sha256": "6d5310debc563fa2a337548834094beafe271e5130a0ade9834296236edbc807" }, "downloads": -1, "filename": "json_checker-1.2.0.tar.gz", "has_sig": false, "md5_digest": "750e637b3930effb9c3600732e73d59b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10701, "upload_time": "2018-02-28T09:32:44", "url": "https://files.pythonhosted.org/packages/e3/cf/264a95a610e0f37cadb1090481c0d5786680d94415aa5e33c21567706015/json_checker-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "7120f7098fb7e8261ffb90ad6322712c", "sha256": "4a74701b36e7acf0add1004f0d23d5a8c46c29af4992acb1450168f4e5b389eb" }, "downloads": -1, "filename": "json_checker-1.2.1.tar.gz", "has_sig": false, "md5_digest": "7120f7098fb7e8261ffb90ad6322712c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 10902, "upload_time": "2018-03-20T11:09:14", "url": "https://files.pythonhosted.org/packages/e9/51/49837e7b41b867f83a8584122688b71841010ea890dee96cb34cc691c223/json_checker-1.2.1.tar.gz" } ], "1.2.2": [ { "comment_text": "", "digests": { "md5": "fcbb3141690f312d5456261f30db8218", "sha256": "e080f7b64df253f82faf103bd5dc2b66312cda3cac2ea84d2df50e20c201f2e5" }, "downloads": -1, "filename": "json_checker-1.2.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "fcbb3141690f312d5456261f30db8218", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 11620, "upload_time": "2018-12-28T16:42:08", "url": "https://files.pythonhosted.org/packages/fe/04/c45400c8e2ccdd4161ee889eeb518a915737ad89344b2b374e488d20b458/json_checker-1.2.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b4e4a85adc5d572feb45f0aeb083bcf6", "sha256": "5c0a62fa942244df0cf7aed95a125f017ab7eabc548657b1088aea962a44fa61" }, "downloads": -1, "filename": "json_checker-1.2.2.tar.gz", "has_sig": false, "md5_digest": "b4e4a85adc5d572feb45f0aeb083bcf6", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 10478, "upload_time": "2018-12-28T16:42:11", "url": "https://files.pythonhosted.org/packages/3d/b6/e1bd30f50b4095891c0d2867c2a56a8104b0a5478de3235440af3016edce/json_checker-1.2.2.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "249c5225802e37c9cb87cdcdebe3f7c2", "sha256": "a1e013d5b6bc0acea9cab0e2a4378fcd54be7afa638d8ab67350a4b4f1f3baf9" }, "downloads": -1, "filename": "json_checker-1.2.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "249c5225802e37c9cb87cdcdebe3f7c2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 11620, "upload_time": "2018-12-28T16:42:10", "url": "https://files.pythonhosted.org/packages/53/02/1f3834e0875666ff5b3ff10b06d61dad2f5d54d4f3eb366b940ebe39a0b8/json_checker-1.2.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ae67d20a4a77c1809f4513883a68b03e", "sha256": "10fd3d8957718dd5cee13dee9ab457ef9e86a6fea85b8f787158dbcbb5eed9dc" }, "downloads": -1, "filename": "json_checker-1.2.3.tar.gz", "has_sig": false, "md5_digest": "ae67d20a4a77c1809f4513883a68b03e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 10477, "upload_time": "2018-12-28T16:42:12", "url": "https://files.pythonhosted.org/packages/37/74/18e7e33f4d2eafd41c74be1bff0f8e116ca09e6ebc32b6ac12d4a9c1525e/json_checker-1.2.3.tar.gz" } ], "1.3.1": [ { "comment_text": "", "digests": { "md5": "ef4a22eae1477cf1fec0b598385a9345", "sha256": "b17c4b8c0b3be3a5c7031d62b09885631238a8b349d4a2e092ead62632702811" }, "downloads": -1, "filename": "json_checker-1.3.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ef4a22eae1477cf1fec0b598385a9345", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7", "size": 13790, "upload_time": "2019-06-19T10:34:34", "url": "https://files.pythonhosted.org/packages/60/d3/1188e92dd382dc325b0e62e01f6f468ef03045b4ca0eafeb4ab9c0621870/json_checker-1.3.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "65f53958fa0d54262e2b395bad97b110", "sha256": "4e8e6ca68cb599076fcaccf0280cab0f18eb174438d1b394c17eb033cd1acc31" }, "downloads": -1, "filename": "json_checker-1.3.1.tar.gz", "has_sig": false, "md5_digest": "65f53958fa0d54262e2b395bad97b110", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 11872, "upload_time": "2019-06-19T10:34:36", "url": "https://files.pythonhosted.org/packages/cd/90/86e5e6d9c2dadc546ccfbe609c1b6264b1c232fbd32c5cc2b4f8955d17a4/json_checker-1.3.1.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "8ed26958b90a1eac8c2732c73be786cc", "sha256": "2398f761549709198f8cbd778a731c78cc0ab70e3299e1b8898f8bc8c7dd2b57" }, "downloads": -1, "filename": "json_checker-2.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8ed26958b90a1eac8c2732c73be786cc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 19108, "upload_time": "2019-08-31T14:00:37", "url": "https://files.pythonhosted.org/packages/fd/3c/2f5cb8880a05aa6a2456a6a55f2694007cde08baed3732b34a070132462e/json_checker-2.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "81804f721011613ccdad03b6aab09df8", "sha256": "ef32754928b178c74b1f93fb2dbbe7f22f1ce9bc781ea68c28843d9f04d4a8e1" }, "downloads": -1, "filename": "json_checker-2.0.0.tar.gz", "has_sig": false, "md5_digest": "81804f721011613ccdad03b6aab09df8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14898, "upload_time": "2019-08-31T14:00:39", "url": "https://files.pythonhosted.org/packages/9f/22/d742329cf03f9edcb58dc673f39608d0bf57046e99770d2c45ea88709986/json_checker-2.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8ed26958b90a1eac8c2732c73be786cc", "sha256": "2398f761549709198f8cbd778a731c78cc0ab70e3299e1b8898f8bc8c7dd2b57" }, "downloads": -1, "filename": "json_checker-2.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8ed26958b90a1eac8c2732c73be786cc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.6", "size": 19108, "upload_time": "2019-08-31T14:00:37", "url": "https://files.pythonhosted.org/packages/fd/3c/2f5cb8880a05aa6a2456a6a55f2694007cde08baed3732b34a070132462e/json_checker-2.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "81804f721011613ccdad03b6aab09df8", "sha256": "ef32754928b178c74b1f93fb2dbbe7f22f1ce9bc781ea68c28843d9f04d4a8e1" }, "downloads": -1, "filename": "json_checker-2.0.0.tar.gz", "has_sig": false, "md5_digest": "81804f721011613ccdad03b6aab09df8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14898, "upload_time": "2019-08-31T14:00:39", "url": "https://files.pythonhosted.org/packages/9f/22/d742329cf03f9edcb58dc673f39608d0bf57046e99770d2c45ea88709986/json_checker-2.0.0.tar.gz" } ] }