Fork of ajv
 
 
 
 
Go to file
Evgeny Poberezkin 606e81ad4b full support of remote refs 2015-06-07 21:55:40 +01:00
lib full support of remote refs 2015-06-07 21:55:40 +01:00
spec full support of remote refs 2015-06-07 21:55:40 +01:00
.gitignore inline simple rules 2015-05-30 09:53:04 +01:00
.gitmodules added JSON-schema-test-suite as submodule 2015-06-05 21:35:20 +01:00
LICENSE Initial commit 2015-05-20 00:23:32 +01:00
README.md full support of remote refs 2015-06-07 21:55:40 +01:00
package.json full support of remote refs 2015-06-07 21:55:40 +01:00
try.js refactor with defs; use numbered variable names in different levels 2015-06-03 22:30:04 +01:00

README.md

ajv - Another JSON schema Validator

One of the fastest JSON schema validators. It uses doT templates to generate super-fast validating functions.

JSON-schema standard

ajv implements full JSON-schema draft 4 standard:

  • all validation keywords
  • full support of remote refs (remote schemas have to be pre-loaded)
  • correct string lengths for strings with unicode pairs (can be turned off)
  • formats defined by JSON-schema (can be turned off)

ajv passes all the tests from JSON Schema Test Suite (apart from the one that requires that 1.0 is not an integer).

TODO

  • resolve missing remote refs when schemas are added
  • custom formats (via options)
  • schema validation before compilation
  • bundle compiled templates (doT will be dev dependency)

Install

npm install ajv

Usage

var ajv = require('ajv')(options);
var validate = ajv.compile(schema);
var valid = validate(data);
if (!valid) console.log(validate.errors);

or

// ...
var valid = ajv.validate(schema, data);
// ...

ajv compiles schemas to functions and caches them in both cases (using stringified schema as a key - using json-stable-stringify), so that the next time the same schema is used (not necessarily the same object instance) it won't be compiled again.

Options

  • allErrors: check all rules collecting all errors. Default is to return after the first error.
  • verbose: include the reference to the part of the schema and validated data in errors (false by default).
  • format: validate formats (true by default).
  • meta: add meta-schema so it can be used by other schemas (true by default).
  • uniqueItems: validate uniqueItems (true by default).
  • unicode: calculate correct length of strings with unicode pairs (true by default). Pass false to use .length of strings that is faster, but gives "incorrect" lengths of strings with unicode pairs - each unicode pair is counted as two characters.
  • beautify: format the generated function with js-beautify (the validating function is generated without line-breaks). npm install js-beautify to use this option. true or js-beautify options can be passed.

Tests

git submodule update --init
npm test