83

GitHub - talwrii/short_schema: A succinct JSON schema language: convert JSON sch...

 6 years ago
source link: https://github.com/talwrii/short_schema
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Short Schema

A proof-of-concept succinct JSON schema language. This can be used together with genson to quickly understand the shape of JSON data.

Motivation

JSON is a commonly used machine-readable data format. Placing your data in JSON makes it very easy for people to programmatically use your data. It is, therefore, unsurprising that JSON schemas are written in JSON.

However, machine-readable is not the same as human-readable and even though JSON is more readable than XML it is not as readable as a format explicitly designed to be read by a human.

Purpose of this tool

At present this tool takes JSON schemas in JSON and outputs the same schema in our more human-readable standard.

This can be used together with tools that create JSON schema from sample data to quickly understand the format of json data.

Caveats

  • There is at present no parser for this schema language: only a way of producing this schema from JSON schemas.
  • There may well not support all features of JSON schema only those aspects.

The issue of standardisation can provoke strong opinions. Creating new formats and languages results in people having to understand new things and may require more tooling. The main focus of this tool at present is the understanding of data formats rather than the sharing of these formats.

Installing

pip install git+https://github.com/talwrii/short_schema#egg=short_schema

Examples / Cheat sheet

$ echo '{"one": 1}' | genson  | short_schema
{
    one: integer
}
$ echo '[{"one": 1, "two": [1]}, {"one": 2}]' | genson  | short_schema
[
    {
        one: integer,
        ?two: [integer]
    }
]

Usage

usage: short_schema [-h] [--debug] [--one-line]

A succinct language for json schema

optional arguments:
  -h, --help      show this help message and exit
  --debug         Print debug output
  --one-line, -1  Put all the output on one line

Alternatives and prior work

Other tools approach this problem from the point of view of generating JSON schemas:

This tool very much extends the work of genson and was created in the context of using this tool.

Development

There are tests.

These can be run against various versions of python with tox using: python setup.py test. This is considered the canonical acceptance test for this project.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK