Skip to main content

An extension for json_include to support file inclusion

Project description

json-include is an extended way for JSON to support file inclusion, it has two parts:

  1. A syntax definition called include syntax.

  2. A Python implementation to parse and build JSON file that contains include syntax.

Syntax

json-include supports an extended syntax called include syntax in JSON, formatted as:

{
    "...": "include(<json file name>)"
}

or

{
    "<any key>": "include_text(<text file name>)"
}

The include syntax means that this object (the whole {"...": "include(<json file name>")}) in JSON is a reference to the JSON file named in <json file name> notation, and should be included into its place.

The included JSON should always be an object (dict) rather than an array (list), to prevent implicit meaning and make sure we can get a clear view of the structure without looking into the included JSON files.

In case multiple include statements are used, passing key inside makeUnique adds a random string to each included value at the corresponding key:

{
    "...": "include(<json file name>)",
    "makeUnique": "<key>"
}

In a normal JSON when we want to include another JSON on an attribute, it should be written as follows:

{
    "username": "alice",
    "profile": {
        "...": "include(profile_model.json)"
    }
}

In this JSON a profile_model.json is included to present profile attribute, if the content of profile_model.json is like:

{
    "age": 18,
    "gender": "female"
}

then what we mean by the include syntax is that, when this JSON is being used as a normal JSON, it should be seen as:

{
    "username": "alice",
    "profile": {
        "age": 18,
        "gender": "female"
    }
}

To ture JSON with include syntax into a normal JSON, a build process is needed, that’s what the implementation does.

Python Implementation

Implementation could be of any language as long as it can understand the include syntax and output as expected, this repo contains a Python implementation for use.

Installation

pip install https://github.com/exabyte-io/json_include/archive/master.zip

Usage

import json_include
json_include.build_json(ROOT_DIR, 'example.json')

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

exabyte_json_include-2023.12.23.post0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file exabyte_json_include-2023.12.23.post0.tar.gz.

File metadata

File hashes

Hashes for exabyte_json_include-2023.12.23.post0.tar.gz
Algorithm Hash digest
SHA256 a58c6b1faa92299451bf5b952a801aa944694938bde1e4d86db0503d25eb5d1e
MD5 570a6d6486c29743cfcc9c3819c4bbf2
BLAKE2b-256 e3e501844a4dc28b88f8779b79214b88e7d5e99c7e7bd78951c59ecdc9666269

See more details on using hashes here.

File details

Details for the file exabyte_json_include-2023.12.23.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for exabyte_json_include-2023.12.23.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4f176a03830c53b11e74f0d5cfe1f81e5ce156340e0ff14231f4cafffe694f7
MD5 9058f98c6300b496866044a53c9a7601
BLAKE2b-256 04a3dc3e3e3618cae9cce1a3515fef2ee6ae9ca45ee27ea1bef2d76d465941df

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