Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonvalidatingschemaextractor-0.1.0.tar.gz (1.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonvalidatingschemaextractor-0.1.0-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

File details

Details for the file jsonvalidatingschemaextractor-0.1.0.tar.gz.

File metadata

File hashes

Hashes for jsonvalidatingschemaextractor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86ad826c991f730f27c03769155383ea5f0aca5205b5856e4b2f16386d3afbb5
MD5 3ca536a2d0a1f15748ed97702b6d8dde
BLAKE2b-256 94b5fd156b2531f0df50a0bba013d1f846edffffc91ba909c72b455ebfba7801

See more details on using hashes here.

File details

Details for the file jsonvalidatingschemaextractor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonvalidatingschemaextractor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d84bd2fb64eb7666809056fbd8abb7cf2c1fc3d67dc3101e6ad870cf4e64104b
MD5 ebbd19b2373c1c9f2961b5e6a6ff08ff
BLAKE2b-256 d84816d21ef7ea1308bf86cc5e663ce63017c8c76ecebe1e879fe2fc7429b820

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page