Skip to main content

JSON Variables

Nutshell

This is a non-standard implementation extending JSON pointers:

https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-04

It allows you to reference parts of a JSON document from within the same document from within a sub-string.

In other words, JSON Pointers can handle resolving things like:

{
    "a": "foo",
    "b": "/a"
}

However, this proposes a new variable spec requiring an additional template:

{
    "a": "foo",
    "b": "{{/a}}"
}

By using a template, we can replace sub-strings:

{
    "a": "foo",
    "b": "{{/a}}, bar!"
}

Example

The motivation for this is to try and share settings between the front-end and back-end of an application, settings within the same JSON document can reference each other to prevent repetition. Consider the following document:

{
    "USERNAME_REGEX": "[a-zA-Z0-9._-]{3,30}",
    "USERNAMES_REGEX": "{{/USERNAME_REGEX}}(?:,{{/USERNAME_REGEX}})*",
    "FILE_ID_REGEX": "{{/USERNAME_REGEX}}:\\d+"
}

After de-referencing the variables, you get:

{
    "USERNAME_REGEX": "[a-zA-Z0-9._-]{3,30}",
    "USERNAMES_REGEX": "[a-zA-Z0-9._-]{3,30}(?:,[a-zA-Z0-9._-]{3,30})*",
    "FILE_ID_REGEX": "[a-zA-Z0-9._-]{3,30}:\\d+"
}

The original document is more readable and revisions to the first value only require changing one line.

Metadata

Release files for json_variable 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json_variable 0.0.1
File Size Uploaded Provenance Actions
json_variable-0.0.1.tar.gz 3.2 kB Without provenance Details for json_variable-0.0.1.tar.gz

Release files / json_variable-0.0.1.tar.gz

Download URL json_variable-0.0.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4cd7e0767f39492947904717b022416169656acdd7458f1aa856c6e01aaae079
BLAKE2b-256 checksum
How to use checksums
fc4ffa506fc7ad9fd40c2ec50cff998b327b53f68cf65bfdd83494e486f90a31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for json_variable 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page