Coder Social home page Coder Social logo

json_include's Introduction

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:

{
    "...": "<json file name>"
}

The include syntax means that this object (the whole {"...": "<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 a normal JSON when we want to include another JSON on an attribute, it should be written as follows:

{
    "username": "alice",
    "profile": {
        "...": "<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 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 inclusion
  • [ ] Test circluar inclusion
  • [ ] Test invalid syntax

json_include's People

Contributors

reorx avatar wzyboy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.