JSON schema generated based on draft-v4 of the specification. Note that the full spec if not yet supported. The compiler will be enhanced to support as much as possible. More specifically, there's no support for $ref nodes or special nodes like location (lat, long), etc. These features will be added in future releases or you can always fork and make it better :-)
git clone https://github.com/krg7880/json-schema-generatorcd json-schema-generatornpm install .
Install as cli (NPM)
Run on the command line:
npm install -g json-schema-generator
Then use (for example):
#### JSON PATHjson-schema-generator path/to/input.json -o path/to/output.json#### JSON URLjson-schema-generator https://sample.com/path/to/input.json --jsondir ./source/backup -o ./path/to/dir/#### JSON STDIN | STDOUTcat input.json | json-schema-generator > output.json
Install as lib (NPM)
Run on the command line:
npm install json-schema-generator --save-dev
Then, in your project:
var jsonSchemaGenerator =obj = some: object: trueschemaObj;schemaObj = ;
Usage: json-schema-generator [<target>|--url <url>|--file <file>|--stdin] If <target> is specified, it is interpreted as follows: a protocol (like http://) means url; anything else is treated as path to a local file. If no input file is specified and stdin is provided, stdin is used. Options: --stdin Use stdin as input. --url Remote json document to use as input. --file Local json document to use as input. --schemadir, -o Directory (or file, if ending with .json) where the schema will be stored. --jsondir Directory (or file, if ending with .json) where the source document is copied to. Useful with --url. --pretty Whether to use pretty json format. Use --no-pretty for false. [default: true] --force, -f If a destination file already exists, overwrite it. --help, -h Show this help text.
I created this schema generator to validate JSON responses from APIs. As the JSON API is enhanced and nodes are added or removed from the response, the schema is regenerated and validated against the newly deployed API.
To run tests, including fetching documents via HTTP, we've added node-stubby-server-cli to help with serving mock data. The ports for the stub server is defined under test/helpers/stubby-cli, in the event the default port is in use, you can change them there.
npm install -g stubby
Install mocha globally (as cli) and run
Thanks to those who have contributed. These kind folks are listed below: