Skip to main content

JSON Reference and JSON Pointer implementations

Project description


This python package implements the JSON Reference and JSON Pointer specifications in the context of processing JSON and YAML content, such as Swagger and OpenAPI specifications.

JSON Reference

JSON Reference defines a mechanism to reference and include content from the same or separate documents. This helps with maintenance of structured data and documents by reducing repetition, and allowing for the organization of larger documents across multiple files.

JSON Pointer

JSON Pointer defines a syntax for identifying specific portions of a JSON value.

In a document, a JSON Reference takes the form of an object, mapping '$ref' to a reference; other keys in the object are ignored. The reference itself takes the form of a URI. As an example:

{ "$ref": "" }

In this implementation, the URI may reference a JSON or YAML file available in the local filesystem, or served from the network over HTTP/HTTPS. The fragment portion of the URI is interpreted as a JSON Pointer.

Usage example

Find the example below also as in the source repository.

import os
import textwrap

import jref.context
import jref.pointer

# All references are evaluated in a context, so start with one
ctx = jref.context.RemoteContext()

# Reference a remote document
spec = ctx.parse_reference('')

# Reference portions of that document
spec_title = spec.context.parse_reference('#/info/title')
spec_version = spec.context.parse_reference('#/info/version')

# Print out the references, not the content (which hasn't been loaded)
    * JSON References
    Spec:    {}
    Title:   {}
    Version: {}
    .format(spec, spec_title, spec_version))

# Expand references, triggering loading of content
    * Evaluated references
    Title:   {}
    Version: {}
    .format(spec_title.expand(), spec_version.expand()))

Expected output:

* JSON References

* Evaluated references
Title:   Swagger Petstore
Version: 1.0.0


Project details

Download files

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

Files for jref, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size jref-0.1.1-py2.py3-none-any.whl (23.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size jref-0.1.1.tar.gz (14.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page