Skip to main content

Strictly checks that a json schema is valid

Project description

# perfect-jsonschema
[![Build Status](https://travis-ci.org/manycoding/perfect-jsonschema.svg?branch=master)](https://travis-ci.org/manycoding/perfect-jsonschema)
[![codecov](https://codecov.io/gh/manycoding/perfect-jsonschema/branch/master/graph/badge.svg)](https://codecov.io/gh/manycoding/perfect-jsonschema)
---
_Because soft validation is not enough_

# Why
[JSON schema standard](https://json-schema.org/) 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](https://python-jsonschema.readthedocs.io/en/latest/validate/#validating-formats).

The library rely on [jsonschema](https://github.com/Julian/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.5.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: perfect-jsonschema-2019.2.5.tar.gz
  • Upload date:
  • Size: 11.6 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.5.tar.gz
Algorithm Hash digest
SHA256 b6fc3458644fcc1c634cc2361c1d0cfa031b7b785c71a7620b1e86bd836dc455
MD5 396c74fb1e6cbf527af539cfe2632050
BLAKE2b-256 584687376dc28f326644ac0434938d4d76bfc1fac1915fdedcb2e9dcf7d534d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perfect_jsonschema-2019.2.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 94b131c06ca3a6b906c591929ec4ad58470dd91fed0a7205674a2eb9c592dedc
MD5 29366ad2cb433304fa88d72168fb656c
BLAKE2b-256 22acd9a8f5aa92ed6a4a6464e649e6a0f91c8bcceca1bd274df6d3dffa42a603

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