Name | jsonref JSON |
Version |
1.1.0
JSON |
| download |
home_page | |
Summary | jsonref is a library for automatic dereferencing of JSON Reference objects for Python. |
upload_time | 2023-01-16 16:10:04 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# jsonref
[![image](https://github.com/gazpachoking/jsonref/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/gazpachoking/jsonref/actions/workflows/test.yml?query=branch%3Amaster)
[![image](https://readthedocs.org/projects/jsonref/badge/?version=latest)](https://jsonref.readthedocs.io/en/latest/)
[![image](https://coveralls.io/repos/gazpachoking/jsonref/badge.png?branch=master)](https://coveralls.io/r/gazpachoking/jsonref)
[![image](https://img.shields.io/pypi/v/jsonref?color=%2334D058&label=pypi%20package)](https://pypi.org/project/jsonref)
`jsonref` is a library for automatic dereferencing of [JSON
Reference](https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03)
objects for Python (supporting Python 3.7+).
This library lets you use a data structure with JSON reference objects,
as if the references had been replaced with the referent data.
```python console
>>> from pprint import pprint
>>> import jsonref
>>> # An example json document
>>> json_str = """{"real": [1, 2, 3, 4], "ref": {"$ref": "#/real"}}"""
>>> data = jsonref.loads(json_str)
>>> pprint(data) # Reference is not evaluated until here
{'real': [1, 2, 3, 4], 'ref': [1, 2, 3, 4]}
```
# Features
- References are evaluated lazily. Nothing is dereferenced until it is
used.
- Recursive references are supported, and create recursive python data
structures.
References objects are actually replaced by lazy lookup proxy objects
which are almost completely transparent.
```python console
>>> data = jsonref.loads('{"real": [1, 2, 3, 4], "ref": {"$ref": "#/real"}}')
>>> # You can tell it is a proxy by using the type function
>>> type(data["real"]), type(data["ref"])
(<class 'list'>, <class 'jsonref.JsonRef'>)
>>> # You have direct access to the referent data with the __subject__
>>> # attribute
>>> type(data["ref"].__subject__)
<class 'list'>
>>> # If you need to get at the reference object
>>> data["ref"].__reference__
{'$ref': '#/real'}
>>> # Other than that you can use the proxy just like the underlying object
>>> ref = data["ref"]
>>> isinstance(ref, list)
True
>>> data["real"] == ref
True
>>> ref.append(5)
>>> del ref[0]
>>> # Actions on the reference affect the real data (if it is mutable)
>>> pprint(data)
{'real': [2, 3, 4, 5], 'ref': [2, 3, 4, 5]}
```
Raw data
{
"_id": null,
"home_page": "",
"name": "jsonref",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Chase Sterling <chase.sterling@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/aa/0d/c1f3277e90ccdb50d33ed5ba1ec5b3f0a242ed8c1b1a85d3afeb68464dca/jsonref-1.1.0.tar.gz",
"platform": null,
"description": "# jsonref\n\n[![image](https://github.com/gazpachoking/jsonref/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/gazpachoking/jsonref/actions/workflows/test.yml?query=branch%3Amaster)\n[![image](https://readthedocs.org/projects/jsonref/badge/?version=latest)](https://jsonref.readthedocs.io/en/latest/)\n[![image](https://coveralls.io/repos/gazpachoking/jsonref/badge.png?branch=master)](https://coveralls.io/r/gazpachoking/jsonref)\n[![image](https://img.shields.io/pypi/v/jsonref?color=%2334D058&label=pypi%20package)](https://pypi.org/project/jsonref)\n\n`jsonref` is a library for automatic dereferencing of [JSON\nReference](https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03)\nobjects for Python (supporting Python 3.7+).\n\nThis library lets you use a data structure with JSON reference objects,\nas if the references had been replaced with the referent data.\n\n```python console\n>>> from pprint import pprint\n>>> import jsonref\n\n>>> # An example json document\n>>> json_str = \"\"\"{\"real\": [1, 2, 3, 4], \"ref\": {\"$ref\": \"#/real\"}}\"\"\"\n>>> data = jsonref.loads(json_str)\n>>> pprint(data) # Reference is not evaluated until here\n{'real': [1, 2, 3, 4], 'ref': [1, 2, 3, 4]}\n```\n\n# Features\n\n- References are evaluated lazily. Nothing is dereferenced until it is\n used.\n- Recursive references are supported, and create recursive python data\n structures.\n\nReferences objects are actually replaced by lazy lookup proxy objects\nwhich are almost completely transparent.\n\n```python console\n>>> data = jsonref.loads('{\"real\": [1, 2, 3, 4], \"ref\": {\"$ref\": \"#/real\"}}')\n>>> # You can tell it is a proxy by using the type function\n>>> type(data[\"real\"]), type(data[\"ref\"])\n(<class 'list'>, <class 'jsonref.JsonRef'>)\n>>> # You have direct access to the referent data with the __subject__\n>>> # attribute\n>>> type(data[\"ref\"].__subject__)\n<class 'list'>\n>>> # If you need to get at the reference object\n>>> data[\"ref\"].__reference__\n{'$ref': '#/real'}\n>>> # Other than that you can use the proxy just like the underlying object\n>>> ref = data[\"ref\"]\n>>> isinstance(ref, list)\nTrue\n>>> data[\"real\"] == ref\nTrue\n>>> ref.append(5)\n>>> del ref[0]\n>>> # Actions on the reference affect the real data (if it is mutable)\n>>> pprint(data)\n{'real': [2, 3, 4, 5], 'ref': [2, 3, 4, 5]}\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "jsonref is a library for automatic dereferencing of JSON Reference objects for Python.",
"version": "1.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0cece1db9922bceb168197a558a2b8c03a7963f1afe93517ddd3cf99f202f996",
"md5": "09264b1311a8cf6194978cb1799d07e4",
"sha256": "590dc7773df6c21cbf948b5dac07a72a251db28b0238ceecce0a2abfa8ec30a9"
},
"downloads": -1,
"filename": "jsonref-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "09264b1311a8cf6194978cb1799d07e4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9425,
"upload_time": "2023-01-16T16:10:02",
"upload_time_iso_8601": "2023-01-16T16:10:02.255075Z",
"url": "https://files.pythonhosted.org/packages/0c/ec/e1db9922bceb168197a558a2b8c03a7963f1afe93517ddd3cf99f202f996/jsonref-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aa0dc1f3277e90ccdb50d33ed5ba1ec5b3f0a242ed8c1b1a85d3afeb68464dca",
"md5": "c6bb6e762afc840dbb246fbcfeea6800",
"sha256": "32fe8e1d85af0fdefbebce950af85590b22b60f9e95443176adbde4e1ecea552"
},
"downloads": -1,
"filename": "jsonref-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "c6bb6e762afc840dbb246fbcfeea6800",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8814,
"upload_time": "2023-01-16T16:10:04",
"upload_time_iso_8601": "2023-01-16T16:10:04.455770Z",
"url": "https://files.pythonhosted.org/packages/aa/0d/c1f3277e90ccdb50d33ed5ba1ec5b3f0a242ed8c1b1a85d3afeb68464dca/jsonref-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-16 16:10:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "jsonref"
}