vitesse-jsonspec
v1.0.1
Published
JSONSpec validator library leveraging vitesse for high performance validation
Downloads
15
Maintainers
Readme
Vitesse JSON Schema Validator
The Vitesse JSON Schema Validator leverages the Vitesse library to allow you to enjoy high performance JSON Schema validation compliant with the 4th Draft of JSON Schema.
To use the validation library simply do the following.
var Compiler = require('vitesse-jsonspec');
// Our Draft 4 schema
var schema = {
"properties": {
"foo": {
"type": "integer",
"default": []
}
}
var compiler = new Compiler();
compiler.compile(schema, {closure:false}, function(err, validator) {
var results = validator.validate({a:1});
console.dir(results);
});
The options
object supports a single value closure:boolean
that if set to true will make Vitesse attempt to compile the schema using the Google Closure compiler.
The compiler
function will also perform $ref
resolution of schemas, fetching the needed resources from the internet. If you don't have $ref
schema entries or do not wish to use the Closure Compiler you can use the compileSync
method instead.
var Compiler = require('vitesse-jsonspec');
// Our Draft 4 schema
var schema = {
"properties": {
"foo": {
"type": "integer",
"default": []
}
}
var compiler = new Compiler();
var validator = compiler.compileSync(schema)
var results = validator.validate({a:1});
console.dir(results);