Json Spec
=========
.. image:: https://badge.fury.io/py/json-spec.png
:target: http://badge.fury.io/py/json-spec
.. image:: https://travis-ci.org/johnnoone/json-spec.png?branch=master
:target: https://travis-ci.org/johnnoone/json-spec
This library implements several JSON specs, like `JSON Schema`_,
`JSON Reference`_ and `JSON Pointer`_:
* It works on python 3.6 and above
* It is release under the `BSD license`_
Installation
------------
This library has only weak dependencies. You can simply use pip::
$ pip install json-spec
Regading you needs, you can install more features. For example, this command
will enable colorated messages::
$ pip install json-spec[cli]
This one will enable ip format for json schema::
$ pip install json-spec[ip]
...
CLI Usage
---------
This module expose a cli command with multiple operations.
**json add** will transform the json document::
$ json add '#/foo/1' --fragment-file=fragment.json --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json add '#/foo/1' --fragment-json='first'
$ json add '#/foo/1' --fragment-file=fragment.json --document-file=doc.json
$ json add '#/foo/1' --fragment-file=fragment.json < doc.json
**json check** will test that a value at the target location is equal to a specified value::
$ json check '#/foo/1' --fragment-file=fragment.json --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json check '#/foo/1' --fragment-file=fragment.json
$ json check '#/foo/1' --fragment-file=fragment.json --document-file=doc.json
$ json check '#/foo/1' --fragment-file=fragment.json < doc.json
**json copy** will copy the value at a specified location to the target location::
$ json copy '#/foo/1' --target='#/foo/2' --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json copy '#/foo/1' --target='#/foo/2'
$ json copy '#/foo/1' --target='#/foo/2' --document-file=doc.json
$ json copy '#/foo/1' --target='#/foo/2' < doc.json
**json extract** will extract parts of your json document::
$ json extract '#/foo/1' --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json extract '#/foo/1'
$ json extract '#/foo/1' --document-file=doc.json
$ json extract '#/foo/1' < doc.json
**json move** will remove the value at a specified location and it will add the value to the target location::
$ json move '#/foo/2' --target='#/foo/1' --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json move '#/foo/2' --target='#/foo/1'
$ json move '#/foo/2' --target='#/foo/1' --document-file=doc.json
$ json move '#/foo/2' --target='#/foo/1' < doc.json
**json remove** will remove the value at a specified location::
$ json remove '#/foo/1' --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json remove '#/foo/1'
$ json remove '#/foo/1' --document-file=doc.json
$ json remove '#/foo/1' < doc.json
**json replace** will replace the value at a specified location with given fragment::
$ json replace '#/foo/1' --fragment-file=fragment.json --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json replace '#/foo/1' --fragment-file=fragment.json
$ json replace '#/foo/1' --fragment-file=fragment.json --document-file=doc.json
$ json replace '#/foo/1' --fragment-file=fragment.json < doc.json
**json validate** will validate your document against a schema::
$ json validate --schema-file=schema.json --document-json='{"foo": ["bar", "baz"]}'
$ echo '{"foo": ["bar", "baz"]}' | json validate --schema-file=schema.json
$ json validate --schema-file=schema.json --document-file=doc.json
$ json validate --schema-file=schema.json < doc.json
Library usage
-------------
Let say you want to fetch / validate JSON like objects in you python scripts.
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_.
.. _`JSON Schema`: http://json-schema.org
.. _`JSON Reference`: http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03
.. _`JSON Pointer`: http://tools.ietf.org/html/rfc6901
.. _`BSD license`: https://github.com/johnnoone/json-spec/blob/master/LICENSE
.. _documentation: http://py.errorist.io/json-spec/
.. _tests: https://github.com/johnnoone/json-spec/tree/master/tests
Raw data
{
"_id": null,
"home_page": "https://json-spec.readthedocs.org",
"name": "json-spec",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "json, utilitaries, validation, json-pointer, json-reference, json-schema",
"author": "Xavier Barbosa",
"author_email": "clint.northwood@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4d/47/84e030fb7764bd716d2fb58d4bd45c006b407cd413f472a60f1e09265ceb/json_spec-0.12.0.tar.gz",
"platform": null,
"description": "Json Spec\n=========\n\n.. image:: https://badge.fury.io/py/json-spec.png\n :target: http://badge.fury.io/py/json-spec\n\n.. image:: https://travis-ci.org/johnnoone/json-spec.png?branch=master\n :target: https://travis-ci.org/johnnoone/json-spec\n\nThis library implements several JSON specs, like `JSON Schema`_,\n`JSON Reference`_ and `JSON Pointer`_:\n\n* It works on python 3.6 and above\n* It is release under the `BSD license`_\n\n\nInstallation\n------------\n\nThis library has only weak dependencies. You can simply use pip::\n\n $ pip install json-spec\n\nRegading you needs, you can install more features. For example, this command\nwill enable colorated messages::\n\n $ pip install json-spec[cli]\n\nThis one will enable ip format for json schema::\n\n $ pip install json-spec[ip]\n\n...\n\n\nCLI Usage\n---------\n\nThis module expose a cli command with multiple operations.\n\n**json add** will transform the json document::\n\n $ json add '#/foo/1' --fragment-file=fragment.json --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json add '#/foo/1' --fragment-json='first'\n $ json add '#/foo/1' --fragment-file=fragment.json --document-file=doc.json\n $ json add '#/foo/1' --fragment-file=fragment.json < doc.json\n\n**json check** will test that a value at the target location is equal to a specified value::\n\n $ json check '#/foo/1' --fragment-file=fragment.json --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json check '#/foo/1' --fragment-file=fragment.json\n $ json check '#/foo/1' --fragment-file=fragment.json --document-file=doc.json\n $ json check '#/foo/1' --fragment-file=fragment.json < doc.json\n\n**json copy** will copy the value at a specified location to the target location::\n\n $ json copy '#/foo/1' --target='#/foo/2' --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json copy '#/foo/1' --target='#/foo/2'\n $ json copy '#/foo/1' --target='#/foo/2' --document-file=doc.json\n $ json copy '#/foo/1' --target='#/foo/2' < doc.json\n\n**json extract** will extract parts of your json document::\n\n $ json extract '#/foo/1' --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json extract '#/foo/1'\n $ json extract '#/foo/1' --document-file=doc.json\n $ json extract '#/foo/1' < doc.json\n\n**json move** will remove the value at a specified location and it will add the value to the target location::\n\n $ json move '#/foo/2' --target='#/foo/1' --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json move '#/foo/2' --target='#/foo/1'\n $ json move '#/foo/2' --target='#/foo/1' --document-file=doc.json\n $ json move '#/foo/2' --target='#/foo/1' < doc.json\n\n**json remove** will remove the value at a specified location::\n\n $ json remove '#/foo/1' --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json remove '#/foo/1'\n $ json remove '#/foo/1' --document-file=doc.json\n $ json remove '#/foo/1' < doc.json\n\n**json replace** will replace the value at a specified location with given fragment::\n\n $ json replace '#/foo/1' --fragment-file=fragment.json --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json replace '#/foo/1' --fragment-file=fragment.json\n $ json replace '#/foo/1' --fragment-file=fragment.json --document-file=doc.json\n $ json replace '#/foo/1' --fragment-file=fragment.json < doc.json\n\n**json validate** will validate your document against a schema::\n\n $ json validate --schema-file=schema.json --document-json='{\"foo\": [\"bar\", \"baz\"]}'\n $ echo '{\"foo\": [\"bar\", \"baz\"]}' | json validate --schema-file=schema.json\n $ json validate --schema-file=schema.json --document-file=doc.json\n $ json validate --schema-file=schema.json < doc.json\n\n\nLibrary usage\n-------------\n\nLet say you want to fetch / validate JSON like objects in you python scripts.\n\nYou can extract member of an object with `JSON Pointer`_::\n\n from jsonspec.pointer import extract\n\n obj = {\n 'foo': ['bar', 'baz', 'quux']\n }\n assert 'baz' == extract(obj, '/foo/1')\n\n\nYou can resolve member of any object with `JSON Reference`_::\n\n from jsonspec.reference import resolve\n\n obj = {\n 'foo': ['bar', 'baz', {\n '$ref': '#/sub'\n }],\n 'sub': 'quux'\n }\n\n assert 'quux' == resolve(obj, '#/foo/2')\n\n\nYou can describe you data with `JSON Schema`_::\n\n from jsonspec.validators import load\n\n # data will validate against this schema\n validator = load({\n 'title': 'Example Schema',\n 'type': 'object',\n 'properties': {\n 'age': {\n 'description': 'Age in years',\n 'minimum': 0,\n 'type': 'integer'\n },\n 'firstName': {\n 'type': 'string'\n },\n 'lastName': {\n 'type': 'string'\n }\n },\n 'required': [\n 'firstName',\n 'lastName'\n ]\n })\n\n # validate this data\n validator.validate({\n 'firstName': 'John',\n 'lastName': 'Noone',\n 'age': 33,\n })\n\nOther examples can be found in the documentation_ or in the tests_.\n\n.. _`JSON Schema`: http://json-schema.org\n.. _`JSON Reference`: http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03\n.. _`JSON Pointer`: http://tools.ietf.org/html/rfc6901\n.. _`BSD license`: https://github.com/johnnoone/json-spec/blob/master/LICENSE\n.. _documentation: http://py.errorist.io/json-spec/\n.. _tests: https://github.com/johnnoone/json-spec/tree/master/tests\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Implements JSON Schema, JSON Pointer and JSON Reference.",
"version": "0.12.0",
"project_urls": {
"Documentation": "https://json-spec.readthedocs.org",
"Homepage": "https://json-spec.readthedocs.org",
"Repository": "https://github.com/johnnoone/json-spec"
},
"split_keywords": [
"json",
" utilitaries",
" validation",
" json-pointer",
" json-reference",
" json-schema"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c07c31574832b5269f7a9385cec3b9b19d0a535f5ace075446ca9cbb240868bc",
"md5": "bc67127ba951d8385fba17bd98f93db1",
"sha256": "5096695f1ed4d2bf70b04bee792615cc36f8f830f5a5a2255fc43731e4deba1e"
},
"downloads": -1,
"filename": "json_spec-0.12.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc67127ba951d8385fba17bd98f93db1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 42174,
"upload_time": "2024-04-29T11:55:54",
"upload_time_iso_8601": "2024-04-29T11:55:54.010146Z",
"url": "https://files.pythonhosted.org/packages/c0/7c/31574832b5269f7a9385cec3b9b19d0a535f5ace075446ca9cbb240868bc/json_spec-0.12.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4d4784e030fb7764bd716d2fb58d4bd45c006b407cd413f472a60f1e09265ceb",
"md5": "82ee644e828581fbd706763dc64d25f1",
"sha256": "0a1fe48bf3e6bce39668b4bacb99e479429138d77b16ab25c482b3238d4702e0"
},
"downloads": -1,
"filename": "json_spec-0.12.0.tar.gz",
"has_sig": false,
"md5_digest": "82ee644e828581fbd706763dc64d25f1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 29658,
"upload_time": "2024-04-29T11:55:55",
"upload_time_iso_8601": "2024-04-29T11:55:55.958482Z",
"url": "https://files.pythonhosted.org/packages/4d/47/84e030fb7764bd716d2fb58d4bd45c006b407cd413f472a60f1e09265ceb/json_spec-0.12.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-29 11:55:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "johnnoone",
"github_project": "json-spec",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "json-spec"
}