Implements JSON Schema, JSON Pointer and JSON Reference.
Project description
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-spec
Usage
Let say you want to fetch / validate JSON like objects.
You can extract member of an object with JSON Pointer:
from jsonspec.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 jsonspec.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 jsonspec.validators 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
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
json-spec-0.9.5.tar.gz
(62.0 kB
view hashes)
Built Distribution
Close
Hashes for json_spec-0.9.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91745fe934d09f1be159a9100c2ff8124e6b56fa72496e97d6ed505d9b9eb1b5 |
|
MD5 | 0cef4144344a75b78e79678e03822dff |
|
BLAKE2b-256 | b7645d985cb08fcdf4cd724e843b6ca194db08c9e7b27a38e7b26fea89393b8e |