JSON Schema validator
Tools to generate Python types based on TypedDict from a JSON schema
Quick start
install:
python3 -m pip install jsonschema-validator-new
Convert a JSON schema to a Python file contains the types:
jsonschema-validator --help
Default
The default values are exported in the Python file, then you can do something like that:
value_with_default = my_object.get('field_name', my_schema.FIELD_DEFAULT)
Validation
This package also provide some validations features for YAML file based on jsonschema.
Additional features:
- Obtain the line and columns number in the errors, if the file is loaded with
ruamel.yaml. - Export the default provided in the JSON schema.
import ruamel.yaml
import pkgutil
import jsonschema_validator
import json
schema_data = pkgutil.get_data("<package>", "schema.json")
schema = json.loads(jsonschema_validator)
with open(filename) as data_file:
yaml = ruamel.yaml.YAML() # type: ignore
data = yaml.load(data_file)
errors, _ = jsonschema_validator.validate(filename, data, schema)
if errors:
print("\n".join(errors))
sys.exit(1)
Pre-commit hooks
This project provides pre-commit hooks to automatically generate the files.
repos:
- repo: https://github.com/camptocamp/jsonschema-validator
rev: <version> # Use the ref you want to point at
hools:
- id: jsonschema-validator
files: |
(?x)^(
...
)$
Contributing
Install the pre-commit hooks:
pip install pre-commit
pre-commit install --allow-missing-config
The prospector tests should pass.
The code should be typed.
The code should be tested with pytests.
Metadata
Release files for jsonschema-validator-new 0.3.2
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 |
|---|---|---|---|---|
| jsonschema_validator_new-0.3.2.tar.gz | 6.8 kB | Without provenance | Details for jsonschema_validator_new-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jsonschema_validator_new-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for jsonschema_validator_new-0.3.2-py3-none-any.whl |
Total release size: 14.4 kB
Release files / jsonschema_validator_new-0.3.2.tar.gz
| Download URL | jsonschema_validator_new-0.3.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
622a93406d7ebc14ab40f54f83688ccbf0ee37acf81b9543c82914c5077555ba
|
|
BLAKE2b-256 checksum How to use checksums |
c6d5ed89f08eaa4bf821559a6b2ad79ef32c1186b8a950507e7bd4b1508d5688
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / jsonschema_validator_new-0.3.2-py3-none-any.whl
| Download URL | jsonschema_validator_new-0.3.2-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b18a2b2a6115c00ec879d2dc6f99fc657f1086f62b0abef1484165ff19b1b8d
|
|
BLAKE2b-256 checksum How to use checksums |
d093d1810ebd3594c3cadbf6db26a16425e4b6247fa517f9a7f91bb869d9a6cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for jsonschema-validator-new 0.3.2
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.