vitesse-jsonspec

JSONSpec validator library leveraging vitesse for high performance validation

Usage no npm install needed!

<script type="module">
  import vitesseJsonspec from 'https://cdn.skypack.dev/vitesse-jsonspec';
</script>

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);