Fork of ajv
 
 
 
 
Go to file
Evgeny Poberezkin 951572fdde added JSON-schema-test-suite as submodule 2015-06-05 21:35:20 +01:00
lib replace hasOwnProperty with !== undefined 2015-06-05 19:08:11 +01:00
spec added JSON-schema-test-suite as submodule 2015-06-05 21:35:20 +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 unicode lengths are used by default; tidy up 2015-06-05 00:44:04 +01:00
package.json added JSON-schema-test-suite as submodule 2015-06-05 21:35:20 +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

TODO

  • remote refs
  • 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: if true, ajv checks all rules collecting all errors, otherwise it will return after the first error (false by default)
  • verbose: include the reference to the validated data in the errors (false by default)
  • format: if false, the formats won't be validated (true by default)
  • uniqueItems: if false, uniqueItems keyword will be ignored (true by default, i.e. uniqueItems is checked)
  • unicode: if false, sting.length will be used and the string lengths with unicode pairs will be "incorrect" because each unicode pair will be counted as two characters (true by default - string lengths are calculated correctly but it is slower)