Skip to main content

Sub-string Extension to JSON Pointer References.

Project description

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.

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

json_variable-0.0.1.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file json_variable-0.0.1.tar.gz.

File metadata

File hashes

Hashes for json_variable-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4cd7e0767f39492947904717b022416169656acdd7458f1aa856c6e01aaae079
MD5 bf80a0b1158dcbdaee98c169d66e20d1
BLAKE2b-256 fc4ffa506fc7ad9fd40c2ec50cff998b327b53f68cf65bfdd83494e486f90a31

See more details on using hashes here.

Supported by

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