Skip to main content

An extension for json_include to support file inclusion

Project description

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 krozark-json-include

Usage

import json_include
json_include.build_json('example.json')
json_include.build_json(ROOT_DIR, 'example.json')
json_include.build_str('example.json')
json_include.build_str(ROOT_DIR, 'example.json')
json-build test/source/c.json
python -m json_include test/source/c.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

krozark-json-include-3.3.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

krozark_json_include-3.3.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file krozark-json-include-3.3.1.tar.gz.

File metadata

  • Download URL: krozark-json-include-3.3.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for krozark-json-include-3.3.1.tar.gz
Algorithm Hash digest
SHA256 c126d2653caa5159b89b738e73b258ddb67563679fb349f3823b79fb4f4af519
MD5 0f2e8e83f88a495a9b464723ef6c3050
BLAKE2b-256 47e42868d1c1f4407b3ce1b0596904f4981ee11f7de357f4ed1ecba2e1a3fb37

See more details on using hashes here.

File details

Details for the file krozark_json_include-3.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for krozark_json_include-3.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27f8047d56f460b49dd565af45e85d615f1cf01cd1cb1f66affe37e0c738bd78
MD5 808bd803abf0a7d28e305613ba3a7c13
BLAKE2b-256 38e98e88b8637b42f0233a5e6c9d7a016b4775edb5f80af51a707a1e7e6ffdbc

See more details on using hashes here.

Supported by

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