Skip to main content

Implements sereval JSON specs, like JSON Schema.

Project description

https://badge.fury.io/py/json-extensions.png https://travis-ci.org/johnnoone/json-extensions.png?branch=master https://pypip.in/d/json-extensions/badge.png

This library implements several JSON specs, like JSON Schema, JSON Reference and JSON Pointer:

  • It works on python 2.7, python 3.3 and above

  • It is release under the BSD license

Installation

This library has no special dependencies. You can simply use pip:

$ pip install json-extensions

Usage

Let say you want to fetch / validate JSON like objects.

You can extract member of an object with JSON Pointer:

from json.pointer import extract

obj = {
    'foo': ['bar', 'baz', 'quux']
}
assert 'baz' == extract(obj, '/foo/1')

You can resolve member of any object with JSON Reference:

from json.reference import resolve

obj = {
    'foo': ['bar', 'baz', {
        '$ref': '#/sub'
    }],
    'sub': 'quux'
}

assert 'quux' == resolve(obj, '#/foo/2')

You can describe you data with JSON Schema:

from json.schema import load

# data will validate against this schema
validator = load({
    'title': 'Example Schema',
    'type': 'object',
    'properties': {
        'age': {
            'description': 'Age in years',
            'minimum': 0,
            'type': 'integer'
        },
        'firstName': {
            'type': 'string'
        },
        'lastName': {
            'type': 'string'
        }
    },
    'required': [
        'firstName',
        'lastName'
    ]
})

# validate this data
validator.validate({
    'firstName': 'John',
    'lastName': 'Noone',
    'age': 33,
})

Other examples can be found in the documentation or in the tests.

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

json-extensions-0.2.1.9.g9d1a9cb.tar.gz (27.7 kB view hashes)

Uploaded Source

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