1.0.0 • Published 7 years ago

leason v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Build Status

Leason

A JSON schema learner.

NPM

The concept of Leason is simple: learn the schema by feeding json documents.

Install:

npm i leason -g

CLI:

$ bin/leason

  Usage: leason [options]

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -t, --title        add titles
    -f, --format       try to detect format
    -e, --enum         try to detect enum
    -s, --similar <n>  merge similar objects if `n` or more properties are the same
    -d, --default      add defaults
    -r, --required     add required

  Examples:

    $ leason my.json
    $ cat my.json | leason > schema.json

Script:

var Leason = require('leason');
var json = require('./package.json');

var leason = new Leason()
leason.parse(json);

console.log(leason.schema);

Result:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "main": {
      "type": "string"
    },
    "watch": {
      "type": "object",
      "properties": {
        "test": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "bin": {
      "type": "object",
      "properties": {
        "leason": {
          "type": "string"
        }
      }
    },
    "scripts": {
      "type": "object",
      "properties": {
        "test": {
          "type": "string"
        },
        "watch": {
          "type": "string"
        }
      }
    },
    "author": {
      "type": "string"
    },
    "license": {
      "type": "string"
    },
    "dependencies": {
      "type": "object",
      "properties": {
        "type-of": {
          "type": "string"
        },
        "commander": {
          "type": "string"
        }
      }
    },
    "devDependencies": {
      "type": "object",
      "properties": {
        "js-yaml": {
          "type": "string"
        },
        "tape": {
          "type": "string"
        },
        "tap-spec": {
          "type": "string"
        },
        "glob": {
          "type": "string"
        },
        "npm-watch": {
          "type": "string"
        },
        "jshint": {
          "type": "string"
        }
      }
    }
  }
}

As one can see there still is much to be desired.

Some goals:

  • learn types
  • learn formats (by testing validation)
  • detect enum (just give up after 20) or a certain treshold.
  • advanced. more filters to detect similarity.
  • tresholds for each filter. 95% match, means 5% is probably invalid or not. that's why treshold.
  • description filling
  • optional title setter. just capitalize, humanize.
  • auto refactor common parts into definitions.
1.0.0

7 years ago

0.7.0

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

9 years ago

0.0.2

10 years ago

0.0.1

10 years ago