Git Product home page Git Product logo

jb-clj's Introduction

jb

A tool written in Clojure to perform basic schema inference on JSON inputs, and output a description of the inferred schema.

This project provides two namespaces, jb.core and jb.browse.

jb.core

This module exposes infer-schema, a function that returns a Schema Descriptor given any piece of data.

jb.browse

This module exposes browse, a function that takes a piece of data and returns a compact, human-friendly summary of the input's Schema Descriptor.

Example Usage

Consider the following JSON object:

{
    "foo": 4, 
        "bar": [{
            "baz": "value",
            "nullableField": "not null"
        }, {
            "baz": "another one",
            "optional": 42,
            "nullableField": null
        }]
}

If that object is in the file data.json, we can pipe it through jb.core to see the generated Schema Descriptor

$   cat data.json | lein run -m jb.core
{
    "jb.core/id" : "jb.core/schema.id.object",
    "jb.core/schema.data.object" : {
        "foo" : {
            "jb.core/id" : "jb.core/type.id.always",
            "jb.core/schema" : {
                "jb.core/id" : "jb.core/schema.id.primitive",
                "jb.core/schema.data.primitive" : "java.lang.Integer"
            }
        },
        "bar" : {
            "jb.core/id" : "jb.core/type.id.always",
            "jb.core/schema" : {
                "jb.core/id" : "jb.core/schema.id.listof",
                "jb.core/schema.data.listof" : {
                    "jb.core/id" : "jb.core/type.id.always",
                    "jb.core/schema" : {
                        "jb.core/id" : "jb.core/schema.id.object",
                        "jb.core/schema.data.object" : {
                            "optional" : {
                                "jb.core/id" : "jb.core/type.id.maybe",
                                "jb.core/schema" : {
                                    "jb.core/id" : "jb.core/schema.id.primitive",
                                    "jb.core/schema.data.primitive" : "java.lang.Integer"
                                }
                            },
                            "baz" : {
                                "jb.core/id" : "jb.core/type.id.always",
                                "jb.core/schema" : {
                                    "jb.core/id" : "jb.core/schema.id.primitive",
                                    "jb.core/schema.data.primitive" : "java.lang.String"
                                }
                            },
                            "nullableField" : {
                                "jb.core/id" : "jb.core/type.id.always",
                                "jb.core/schema" : {
                                    "jb.core/id" : "jb.core/schema.id.union",
                                    "jb.core/schema.data.union" : [ {
                                        "jb.core/id" : "jb.core/schema.id.primitive",
                                        "jb.core/schema.data.primitive" : null
                                    }, {
                                        "jb.core/id" : "jb.core/schema.id.primitive",
                                        "jb.core/schema.data.primitive" : "java.lang.String"
                                    } ]
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Consumers of jb.core/infer-schema will see namespaced keywords where you see "jb.core/*" above.

For a more readable summary of the schema, we can use jb.browse.

$   cat data.json | lein run -m jb.browse
{
    "foo" : "java.lang.Integer",
    "bar" : [ {
        "optional" : {
            "maybe" : "java.lang.Integer"
        },
        "baz" : "java.lang.String",
        "nullableField" : {
            "union" : [ null, "java.lang.String" ]
        }
    } ]
}

jb-clj's People

Contributors

anrosent avatar

Stargazers

Yeting Li avatar

Watchers

James Cloos avatar  avatar  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.