Skip to main content

A simple JSON schema checker

Project description

Python JSON Checker

A super-simple library for validating json against a schema.

Install from pip

pip install jsonism

Why use Jsonism?

Jsonism is a great alternative to jsonschema when you just want to do some simple validation of JSON without your code getting horrendously complicated.

It's quick to set up a basic schema checker.

Example usage

Import the checker

from jsonism.checker import validate

The validate function returns True if the input you give it matches the schema that you provide.

Basic flat objects

schema = {
    "Bob": str,
    "Lucy": int,
    "Bert": bool
}
input = {
    "Bob": "Is Bob",
    "Lucy": 13,
    "Bert": True
}
validate(input, schema)

Lists

input = ["Bob", "Alice", "John"]
schema = [str]
validate(input, schema)

Other stuff

input = {"Usernames": [{"username": "Bob", "age": 23}, {"username": "Bill", "age": 98}]}
schema = {"Usernames": [{"username": str, "age": int}]}
validate(input, schema)

Obviously for more complex json, you can json.loads the input.

Permissive validation

Jsonism is permissive when it comes to extra elements. As long as the elements listed in the schema are provided, validate will return True. If additional elements are added to the input, validate will still return True.

schema = {
    "Bob": str,
    "Lucy": int,
    "Bert": bool
}
input = {
    "Bob": "Is Bob",
    "Lucy": 13,
    "Bert": True,
    "Colin": 21
}
validate(input, schema)  # Will return True

But it doesn't have feature x!

Well, I did say it was simple. I plan on allowing optional value validation in a future version. It will always support the very simple initialisation shown above. If you have a burning desire to add a feature, please either post an issue or make a pull request at https://github.com/bmcollier/jsonism.

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

jsonism-1.0.6.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

jsonism-1.0.6-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

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