JSON Schema Defaults
Generate JSON object from default values in JSON Schema
Works both in node and browser.
Installation
Usage
-
CommonJS (node.js)
var defaults = require('json-schema-defaults');
defaults({ ... });
-
RequireJS
paths: {
'defaults': './path/to/lib/defaults.js'
}
define(['defaults'], function(defaults) {
defaults({ ... });
});
-
standalone
window.jsonSchemaDefaults({ ... });
If the standalone version causes any conflict with existing jsonSchemaDefaults
global variable,
you can return back the original variable:
var defaults = window.jsonSchemaDefaults.noConflict();
defaults({ ... });
-
CLI
If installed globally:
json-schema-defaults schema.json
If locally:
./node_modules/.bin/json-schema-defaults schema.json
Custom indentation (defaults to 2):
json-schema-defaults --indent 4 schema.json
Write into a file:
json-schema-defaults schema.json > defaults.json
Documentation
Call defaults
with JSON Schema. The default values will be extracted as a JSON.
var json = defaults({
"title": "Album Options",
"type": "object",
"properties": {
"sort": {
"type": "string",
"default": "id"
},
"per_page": {
"default": 30,
"type": "integer"
}
}
});
{
sort: 'id',
per_page: 30
}
For more examples, see the tests.
Development
Run tests
npm test
Or individually
./node_modules/.bin/jasmine-node test/
./node_modules/karma/bin/karma start
Contributors
- Eugene Tsypkin @jhony-chikens
License
(c) 2015 Chute Corporation. Released under the terms of the MIT License.