Validate and extract values from JSON objects using JSON schema.
Project description
jsonschemaextractor
An extension to JSON schema allowing extracting values from objects declaratively by specifying them in the schema.
Installation
pip install jsonvalidatingschemaextractor
Usage
To extract a value from a JSON object into a field, specify an extract_to property in the JSON schema which contains the name
with which the value should be extracted into the resulting dictionary.
In the example below, we extract the name field in the JSON to a username field in the dictionary.
from jsonschema.validators import Draft7Validator
from jsonvalidatingschemaextractor import Extractor
schema = {
"type": "object",
"properties": {
"name": {
"type": "string",
"extract_to": "username"
}
}
}
validator = Draft7Validator(schema=schema)
extractor = Extractor(validator=validator) # noqa
result = extractor.validate_and_extract({"name": "John Doe"})
assert result.extracted_values == {"username": "John Doe"}
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonvalidatingschemaextractor-0.1.0.tar.gz.
File metadata
- Download URL: jsonvalidatingschemaextractor-0.1.0.tar.gz
- Upload date:
- Size: 1.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.14 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86ad826c991f730f27c03769155383ea5f0aca5205b5856e4b2f16386d3afbb5
|
|
| MD5 |
3ca536a2d0a1f15748ed97702b6d8dde
|
|
| BLAKE2b-256 |
94b5fd156b2531f0df50a0bba013d1f846edffffc91ba909c72b455ebfba7801
|
File details
Details for the file jsonvalidatingschemaextractor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jsonvalidatingschemaextractor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.14 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d84bd2fb64eb7666809056fbd8abb7cf2c1fc3d67dc3101e6ad870cf4e64104b
|
|
| MD5 |
ebbd19b2373c1c9f2961b5e6a6ff08ff
|
|
| BLAKE2b-256 |
d84816d21ef7ea1308bf86cc5e663ce63017c8c76ecebe1e879fe2fc7429b820
|