Skip to main content

Jsonism - The Simple 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

Value validation

This is absolutely optional, in order to keep things as simple as possible and enable the use of the in-built types int, str, bool, and float wherever possible. But we do also support the use of value validation as follows:

from jsonism.checker import validate
from jsonism.types import String, Integer, Boolean, Float

schema = {
    "Bob": String(len=6),
    "Lucy": Integer(max=96),
    "Bert": Boolean(allowed=True),
    "Chris": Float(min=12.34)
}
input = {
    "Bob": "Is Bob",
    "Lucy": 30,
    "Bert": True,
    "Chris": 34.2
}
validate(input, schema)  # Will return True

Lists of valid values

from jsonism.checker import validate
from jsonism.types import String, Integer, Boolean, Float

schema = {
    "Bob": String(options=["Is Bob", "Not Bob"]),
    "Lucy": Integer(max=22),
    "Bert": Boolean(allowed=True)
}
input = {
    "Bob": "Was Bob",
    "Lucy": 22,
    "Bert": True
}
validate(input, schema)  # Will return False

But it doesn't have feature x!

Well, I did say it was simple. It will always support the very simple initialisation shown above. We also now support value validation. 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.

Release files for jsonism 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonism 1.1.2
File Size Uploaded
jsonism-1.1.2.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonism 1.1.2
File Interpreter ABI Platform
jsonism-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / jsonism-1.1.2.tar.gz

Download URL jsonism-1.1.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a386360cbbcc448af365f174a02e290df9e4dae3e19046f22c559f5952d1d164
BLAKE2b-256 checksum
How to use checksums
c0331b55a7c8abdfddfdb67a3fa44ed4642840034038e73d525dbda3a0cbd407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.2

Release files / jsonism-1.1.2-py3-none-any.whl

Download URL jsonism-1.1.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e4debf7678442a62012a8a0a44f3545d6baddfaeac5e84126e22cbcb5ae08ce
BLAKE2b-256 checksum
How to use checksums
ed0bd71a95cd0f9a1714ef32ed3788170c9bb1b0279807e295a81e30716eac13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.0.16

2 release files

1.0.10

1 release file

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page