JVAL - JSON Validation Language - Python Module
pip install jval
JVAL allows for structural and type validation of JSON objects. This project defines the JVAL specification and presents a sample implementation in Python.
Features
JVAL...
- is isomorphic to JSON. This means that it takes the same amount of lines to define a schema as it does to define a JSON object that complies with such schema, no matter how complex you decide to make it.
- supports nested type definitions and optional fields with default values.
- produces descriptive error messages that point to the exact location of the problem.
- will, not only notify you of errors in the JSON object but also in the schema itself, helping you write and understand your schemas.
- can be configured to discard extra fields in the JSON object instead of raising an error if they are present. This enables the usage of JVAL for filtering as well as validation.
- takes specs written in JSON, making syntax highlighting, autocompletion, and formatting available in your favorite text editor out of the box.
A JVAL Schema Example
{
"version": "1.0",
# Expect a "version" key with a value of "1.0"
"*name": "<str>",
# Expect a "name" key with a value of type string
"?compression": "7zip",
# Optional "compression" key. Must have a value of "7zip" if present.
"?*dependencies": ["<str>"],
# Optional "dependencies" key. Must be a list of strings if present.
"?_visibility": "private",
# Optional "visibility" key. Assume a default value of "private" if not present.
# Must be a value of type string if present. (Infers type from default value).
"*addresses": [
# Type requirements can be as complex or simple as you need them to be.
{
"*street": "<str>",
"*number": "<int>",
"?*complement": "<str>",
},
],
}
A schema like the one above is passed to the validator along with a JSON object to validate.
The function will return the validated data, adding any default values that are missing from the input JSON object. If the object does not comply with the schema, it will raise an exception that includes the exact location of the error.
Usage
After installing the package with pip install jval you can either use it as a command line tool or import it in your Python code as a module.
Command-line usage
usage: jval [-h] [--drop-extra-keys] json_path jval_path
Validate JSON data against a JVAL schema.
Positional arguments:
json_path Path to the JSON file to validate
jval_path Path to the JVAL schema file
Options:
-h, --help Show this help message and exit
--drop-extra-keys Drop extra keys in the JSON data that are not defined in the JVAL schema
Python module usage
from jval import validate
schema = {
"*name": "<str>",
"?*age": "<int>",
"?_has_pets": False,
"?*properties": [
{
"*name": "<str>",
"*address": "<str>"
}
]
}
data = {
"name": "Alice",
"properties": [
{
"name": "Long Island Apartment",
"address": "1234 Long Island St."
}
]
}
validated_data = validate(data, schema)
print(validated_data)
Output:
{
"name": "Alice",
"has_pets": False,
"properties": [
{
"name": "Long Island Apartment",
"address": "1234 Long Island St."
}
]
}
Metadata
Release files for jval 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jval-1.0.6.tar.gz | 12.9 kB | Without provenance | Details for jval-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jval-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for jval-1.0.6-py3-none-any.whl |
Total release size: 27.4 kB
Release files / jval-1.0.6.tar.gz
| Download URL | jval-1.0.6.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b64f65ef683e9c64d2cc71dfb95f96a983b61c58eafa9bfe729ad10f7e375e4
|
|
BLAKE2b-256 checksum How to use checksums |
a23e803fe45f40a630909bb7e5c6fbf46544d0c5b4a4d5c9f1adc4131453c884
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Windows/11
|
Release files / jval-1.0.6-py3-none-any.whl
| Download URL | jval-1.0.6-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
febd23951df52b56d1ea54595a7f92745576a26f214b83669c288b1a89d3b3e0
|
|
BLAKE2b-256 checksum How to use checksums |
69730d73f957ab5c902e54c44ebb103f94e1445ac25be939efef34f9088945cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Windows/11
|
Security for jval 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.