Skip to main content

An extension for JSON to support file inclusion

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')

Metadata

Release files for exabyte-json-include 2023.12.23.post0

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

Source distribution (sdist)

Source distribution for exabyte-json-include 2023.12.23.post0
File Size Uploaded
exabyte_json_include-2023.12.23.post0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for exabyte-json-include 2023.12.23.post0
File Interpreter ABI Platform
exabyte_json_include-2023.12.23.post0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / exabyte_json_include-2023.12.23.post0.tar.gz

Download URL exabyte_json_include-2023.12.23.post0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a58c6b1faa92299451bf5b952a801aa944694938bde1e4d86db0503d25eb5d1e
BLAKE2b-256 checksum
How to use checksums
e3e501844a4dc28b88f8779b79214b88e7d5e99c7e7bd78951c59ecdc9666269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / exabyte_json_include-2023.12.23.post0-py3-none-any.whl

Download URL exabyte_json_include-2023.12.23.post0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4f176a03830c53b11e74f0d5cfe1f81e5ce156340e0ff14231f4cafffe694f7
BLAKE2b-256 checksum
How to use checksums
04a3dc3e3e3618cae9cce1a3515fef2ee6ae9ca45ee27ea1bef2d76d465941df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release history Release notifications | RSS feed

This release

2023.12.23.post0 This release

2 release files

2.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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