Skip to main content

An extension for JSON to support file including

Project description

json-include is an extended way for JSON to support file including, 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 one and only one syntax, formatted as:

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

The include syntax means that this object (the whole {"...": "include()"}) in JSON is a reference to the JSON file specified in include(<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 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 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"
    }
}

Python Implementation

Installation

pip install json-include

Usage

By installation a command called json-include will be registerd as an entry point, use it as follows:

usage: json-include [-h] DIR FILE

Command line tool to build JSON file by include syntax.

positional arguments:
  DIR         The directory path of source json files
  FILE        The name of the source json file

optional arguments:
  -h, --help  show this help message and exit

For example:

json-include test/source_json/ c.json

The parsed and built result of c.json will be printed.

Further usage of json_include package is documented in its source code, and test/ can also give you better understandings of how it works.

TODOs

  • [ ] Prevent circluar include

  • [ ] Test circluar include

  • [ ] Test invalid syntax

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-include-0.1.3.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file json-include-0.1.3.tar.gz.

File metadata

  • Download URL: json-include-0.1.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for json-include-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6f39d043fdf88ea542b9e5ccb27366dbc239b4e8adb183d82507627b19c44c0a
MD5 cf9373f46f1663116991c5e2fe858558
BLAKE2b-256 11b6beca28956f05de0aef64e6b877ae86680c46298167268cc06d4102f586d7

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