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.0.tar.gz
(58.4 kB
view hashes)
Built Distribution
Close
Hashes for json_spec-0.9.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 180bb6cd992feaa133403ce9f31ae95bc57625c82329d72afade993208b11681 |
|
MD5 | 6d55ed09b5af3d125d12f42e51f74b8b |
|
BLAKE2b-256 | ca83ae00fd691c44a1de46965786f4d1ebfa0ebc3a64d36bb8ef7cd772b37d8d |