Skip to main content

Strictly checks that a json schema is valid

Project description

perfect-jsonschema

Build Status codecov

Because soft validation is not enough

Why

JSON schema standard and its implementations stand that if you have something unfamiliar in your schema, it's not an error. In particular, you won't get an error if you made a typo or used something you thought as working. For example, this one is perfectly fine and valid:

{
    "required": ["company"],
    "type": "object",
    "propertie": {"company": {"pattern": "^(Apple)$"}, "format": "url"},
}

But we want to catch those propertie typos and invalid url formats.

The library rely on jsonschema and supports additional keywords to ignore.

Features

Derives the draft from the schema and yields a jsonschema.SchemaError if:

  • A schema is empty
  • A schema contains a keyword which is not a part of a jsonschema implementation or extended_keywords set
  • A schema contains an invalid format value
  • A schema fails with jsonschema.check_schema()

Usage

from perfect-jsonschema import check

try:
    check(schema, extended_keywords={"tag"})
except Exception as e:
    do_something()

An exception example:

Traceback (most recent call last):
    f"Schema contains invalid keywords for "
jsonschema.exceptions.SchemaError: Schema contains invalid keywords for http://json-schema.org/draft-07/schema#:
{'propertie', 'company'}

Local development

pipenv install --dev
pipenv shell
tox

Contribution

Any contribution is welcome

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perfect-jsonschema-2019.2.6.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

perfect_jsonschema-2019.2.6-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file perfect-jsonschema-2019.2.6.tar.gz.

File metadata

  • Download URL: perfect-jsonschema-2019.2.6.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for perfect-jsonschema-2019.2.6.tar.gz
Algorithm Hash digest
SHA256 441877f9a9ec32716715acc13b5c28f79a34f98f0823178b2d992fa95526bc00
MD5 b2ce0966b1e0fb2f0543e4e551628997
BLAKE2b-256 987e1c6c39297d09363e88d53e9d805f0cf1bb39dde67a69801d162529b28207

See more details on using hashes here.

File details

Details for the file perfect_jsonschema-2019.2.6-py3-none-any.whl.

File metadata

  • Download URL: perfect_jsonschema-2019.2.6-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for perfect_jsonschema-2019.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0dbb049a48eaa1636cacdd6119fd8e6425561fa7f9b028e926774b26517d7aa4
MD5 c74163ab375872de781ca148ab657c84
BLAKE2b-256 eac1de9bb485f2d7cf7e11ef27a291a80cf31fcc76db59e864d89f21333f656e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page