A JSON/YAML loader
Project description
jacobs-json-doc
A JSON/YAML loader for Python3.
PyYAML or ruamel.yaml do a good job at parsing YAML or JSON into a Python object. This package wraps ruamel.yaml to provide a little bit of extra functionality.
Line Numbers
If you're trying to do use parts of a JSON/YAML document, and you find that the structure of the document didn't conform to a schema or expectations, then you might want to display an error saying something like "On line 123, the value of foo was missing." This package allows easier access to the YAML/JSON line numbers by accessing the .line property.
Dollar References
JSON Schema, OpenAPI, AsyncAPI, and others have a concept of references like this: {"$ref": "other.json#/path/to/definition"}.
The idea here is that instead of the JSON object with the $ref you should be able to get a JSON structure from somewhere else. In this example, you should find a document called other.json and pull out a structure at /path/to/definition.
Loader
A loader object (inherits from jacobsjsondoc.loader.LoaderBaseClass) is able to get the JSON/YAML source. The loader can be different if you are loading from a database, filesystem, http, etc.
Reference Modes
Given a loader, jacobs-json-doc can deal with dollar references. There are two modes for how it can deal with references:
- Use
DocReferenceobjects. Anywhere in the document tree where there is a$refreference, aDocReferenceobject is created. - Automatic resolution. Anywhere in the document tree where there is a
$refreference, the reference is automatically resolved and the$refs are replaced with the structures that they were referencing.
Examples
The test_document.py file is a good source for examples.
A very brief example is:
from jacobsjsondoc.loader import FilesystemLoader
from jacobsjsondoc.document import Document, RefResolutionMode
my_document = "/path/to/example.yaml"
loader = FilesystemLoader()
doc = Document(uri=my_document, loader=loader)
print(doc['a']['b'])
print(doc['a']['b'].line)
If you are loading a single bit of data, without any $ref references, you can do it like this:
import jacobsjsondoc
text_data = '{"hello":"world"}'
doc = jacobsjsondoc.parse(text_data)
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jacobs-json-doc-0.13.1.tar.gz.
File metadata
- Download URL: jacobs-json-doc-0.13.1.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cb7c721282b5e4843086e3338400eff6ea0f57ac7848d8fe92b1853e0128c12
|
|
| MD5 |
2df818de79d1b19c3a9be580e54ccf10
|
|
| BLAKE2b-256 |
6eeb869c07b293643d363d19286f5c609ba85094ef53fab0e2485686aaf4ebc4
|
File details
Details for the file jacobs_json_doc-0.13.1-py3-none-any.whl.
File metadata
- Download URL: jacobs_json_doc-0.13.1-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1f20242d83e65bf14637603dfd1187c1fda9be71a4656965c84ad1295ca26da
|
|
| MD5 |
0734724b414e00ad1513bcf3288eb2af
|
|
| BLAKE2b-256 |
b9faf5c1e69385084296eec74f2fedbb7fedd51414548c2fbdcb62dcbfc6d645
|