Skip to main content

A JSON/YAML loader

Project description

Coverage Status Pearmaster

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.

Fetcher

A fetcher object (inherits from jacobsjsondoc.fetcher.FetcherBaseClass) is able to get the JSON/YAML source. The fetcher can be different if you are loading from a database, filesystem, http, etc.

Reference Modes

Given a fetcher, jacobs-json-doc can deal with dollar references. There are two modes for how it can deal with references:

  • Use DocReference objects. Anywhere in the document tree where there is a $ref reference, a DocReference object is created.
  • Automatic resolution. Anywhere in the document tree where there is a $ref reference, 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.document import create_document

my_document = "/path/to/example.yaml"
doc = create_document(uri=my_document)
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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jacobs_json_doc-0.17.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jacobs_json_doc-0.17.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file jacobs_json_doc-0.17.0.tar.gz.

File metadata

  • Download URL: jacobs_json_doc-0.17.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jacobs_json_doc-0.17.0.tar.gz
Algorithm Hash digest
SHA256 6b3daafc52e1d4e4590d1e66054a98d158ea0710fd431c21ff516b4b74acfcf0
MD5 deb497e24c8df64625bd6d3289e4a057
BLAKE2b-256 6f4cc3eb9aed45bd23358dc5b92cebf7c5b26dc887a96b91dee63472925631a5

See more details on using hashes here.

File details

Details for the file jacobs_json_doc-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: jacobs_json_doc-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jacobs_json_doc-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50d1675525ccf8dd33a239e5ca474316d9fc57705a8dad041b200ab0d8a61aa0
MD5 f3a71477b60f11218656bdb79e28d618
BLAKE2b-256 6ec7600877ad41a786e27bb262b413cd3ee5e99bb1d5796bb776fb68c6298345

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page