Tool to validate files against a JSON Schema
Project description
JSON Schema validator
Tools to generate Python types based on TypedDict from a JSON schema
Quick start
install:
python3 -m pip install --user jsonschema-validator
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
schema_data = pkgutil.get_data("<package>", "schema.json")
with open(filename) as data_file:
yaml = ruamel.yaml.YAML() # type: ignore
data = yaml.load(data_file)
errors, data = 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
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for jsonschema_validator_new-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | deac226a3288222e9f1eb73267e496e33a598270529b31629f2407620a6dde37 |
|
MD5 | 6ccbf7eaaf22ceaed33bbe9d92353978 |
|
BLAKE2b-256 | bd358f4f628092cb0be6c26f22c3813fa3e4e04cf52f870baf943e6758ea2a0f |
Close
Hashes for jsonschema_validator_new-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f93e1a4ca92079f28fbad2b43a1733b5d51c6cc4c7fd327689a63a90b77cf4ff |
|
MD5 | ab628bc155113e29c278a70192ba6227 |
|
BLAKE2b-256 | 29607cc7d6855a2e5e39122683708c1a9b32cc0ca7e7f8ed6926ea33680efa3b |