Giter Site home page Giter Site logo

tiny-json-schema-generator's Introduction

Tiny JSON schema generator

This is a Python package that provides a compact way to define JSON schemas. Here is an example:

schema = {
    'cell_line_id': jst.number,
    'published': jst.boolean_or_null,
    'names': [jst.string_or_null],
    'data': [
        {
            'dataset_id': jst.number_or_null,
            'values': [{'x': jst.number(maximum=1), 'y': jst.number(maximum=1)],
        },
    ]
}

where jst are pre-defined types.

This compact representation is then compiled to its jsonschema-compliant form:

{
    "type": "object",
    "properties": {
        "cell_line_id": {
            "type": ["number", "null"],
            "minimum": 10
        },
        "names": {
            "type": "array",
            "items": {
                "type": ["string", "null"]
            }
        },
        "data": {
            "type": "array",
            "items": {"$ref": "#/$defs/data"}
        }
    },
    "$defs": {
        "data": {
            "type": "object",
            "properties": {
                "dataset_id": {
                    "type": ["number", "null"]
                },
                "value": {
                    "type": "array",
                    "items": {"type": "number", "maximum": 1}
                }
            },
            "$defs": {}
        }
    }
}

Install

conda create -y -n tjsgenv python=3.9
pip install -e '[dev]'

Run tests:

pytest -v

tiny-json-schema-generator's People

Contributors

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