Giter Club home page Giter Club logo

json_spec's Introduction

json_spec

A handy script tool made to convert complex JSON data into human-readable data specs.

WARNING!

This script is mostly undocumented and untested. Use at your own risk.
Also, the spec syntax is a self-made JSON-compatible format meant to be just read by a human. Although the inner spec format can be parsed and manipulated with code, I doubt there would be any software to support it.

Installation

Prerequirements

Steps

  1. Click on the green Code button -> Download ZIP
  2. Unpack the contents in a directory of your choice.

Usage

python json_spec [-h] [-o OUTPUT] [-d DEPTH] [input ...]

Example:

python json_spec sample1.json sample2.json sample3.json

This command will print out the resulted spec.

Notice that you can specify multiple input samples. This allows the script to construct union types from sample data.

Additional arguments

  • -o or --output: specify the output file (instead of printing the result)
  • -d or --depth: set the parsing depth limit (may throw RecursionError for deeply nested JSON with high values)

Spec

The spec syntax supports all JSON types and handles union types with primitives.

(!): Constructing union types requires multiple data samples.
(!): Union types with arrays/objects are not allowed (raise ComplexUnionError).

API

I'm not sure whenever I'll make the API into its own package.
For now, you can use it as-is by copying __init__.py content into your project.

Most useful functions you need to know about:

  • generate_spec(*datas, max_depth: int = 10) - generate a spec from data samples
  • spec_to_json(spec) - convert a spec to JSON-compatible format
  • pprint_spec(spec) - pretty-print a spec

json_spec's People

Contributors

syberiak 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.