Node.js module to validate JSON objects against a JSON Schema, including remote references ($ref)
npm install json-schema-remote[![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Downloads][downloads-image]][npm-url]
> Node.js module to validate JSON objects against a JSON Schema, including remote references ($ref).
``sh`
$ npm install --save json-schema-remote
The module can be used from a Node.js script, or directly on command line.
Node.js ≥ 4.0.0 is required.
`js
const validator = require('json-schema-remote');
validator.validate(data, schema)
.then(() => {
// data is valid!
})
.catch((error) => {
// handle error
});
`
Optionally, a callback can be provided as third parameter. It will be called with (error, isValid).
`sh`when installed globally
json-schema-remote dataURL schemaURLwhen installed locally
./bin/json-schema-remote.js dataURL schemaURL
Validate a JSON against a JSON Schema.
* data is either a JSON object or the URL to a JSON object.schema
* is either a valid JSON schema or the URL to a valid JSON schema.callback
* (optional) is called when validation is finished. Signature:
callback(error, isValid)
* error will contain validation errors (error.errors) or be null if validation succeeded.isValid
* is true when validation succeeded, or false otherwise.
If no callback is provided, the function returns a Promise.
Preload a JSON Schema so it will not be necessary to remotely load it when validating. Synchronous function.
* url can be the id of the schema. May be omitted if schema contains the id property. Otherwise, it will overwrite it.schema
* the Schema to add as JSON
Calls tv4.addSchema internally.
Get a JSON Schema from tv4 cache.
* url URL/ID of the JSON Schema
Calls tv4.getSchema internally.
Set a custom Logging function. Will take console.log else. It is logged when data is loaded over the network.fn
Throws an error if is no function.
``
mocha
Note that the tests need internet access for testing download of remote schemas.
$3
- version 3.0.0 tv4-formats with fixed typescript usage$3
- bugfixes$3
- removed lodash
- split shell usage into single file$3
* updated dependencies$3
* made the feature from 1.1.0 actually work$3
* added function setLoggingFunction(fn) to add a custom logger function instead of console.log$3
* breaking change: Node.js >= 4.0.0 is required due to the usage of Promises and Arrow functions. Use json-schema-remote@0.1.7 for older node versions.
* added support for Promises (callbacks still work, too)
* removed dependency on async`MIT © entrecode GmbH
[npm-url]: https://npmjs.org/package/json-schema-remote
[npm-image]: https://badge.fury.io/js/json-schema-remote.svg
[downloads-image]: http://img.shields.io/npm/dm/json-schema-remote.svg
[daviddm-url]: https://david-dm.org/entrecode/json-schema-remote.svg?theme=shields.io
[daviddm-image]: https://david-dm.org/entrecode/json-schema-remote