Skip to main content

JSONSchema Spec with object-oriented paths

Project description

https://img.shields.io/pypi/v/jsonschema-spec.svg https://travis-ci.org/p1c2u/jsonschema-spec.svg?branch=master https://img.shields.io/codecov/c/github/p1c2u/jsonschema-spec/master.svg?style=flat https://img.shields.io/pypi/pyversions/jsonschema-spec.svg https://img.shields.io/pypi/format/jsonschema-spec.svg https://img.shields.io/pypi/status/jsonschema-spec.svg

About

Object-oriented JSONSchema

Key features

  • Traverse schema like paths

  • Access schema on demand with separate dereferencing accessor layer

Installation

pip install jsonschema-spec

Alternatively you can download the code and install from the repository:

pip install -e git+https://github.com/p1c2u/jsonschema-spec.git#egg=jsonschema_spec

Usage

>>> from jsonschema_spec import SchemaPath

>>> d = {
...     "properties": {
...        "info": {
...            "$ref": "#/$defs/Info",
...        },
...     },
...     "$defs": {
...         "Info": {
...             "properties": {
...                 "title": {
...                     "$ref": "http://example.com",
...                 },
...                 "version": {
...                     "type": "string",
...                     "default": "1.0",
...                 },
...             },
...         },
...     },
... }

>>> path = SchemaPath.from_dict(d)

>>> # Stat keys
>>> "properties" in path
True

>>> # Concatenate paths with /
>>> info_path = path / "properties" / "info"

>>> # Stat keys with implicit dereferencing
>>> "properties" in info_path
True

>>> # Concatenate paths with implicit dereferencing
>>> version_path = info_path / "properties" / "version"

>>> # Open content with implicit dereferencing
>>> with version_path.open() as contents:
...     print(contents)
{'type': 'string', 'default': '1.0'}

License

Copyright (c) 2017-2022, Artur Maciag, All rights reserved. Apache-2.0

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

jsonschema_spec-0.2.4.tar.gz (11.5 kB view hashes)

Uploaded Source

Built Distribution

jsonschema_spec-0.2.4-py3-none-any.whl (14.7 kB view hashes)

Uploaded Python 3

Supported by

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