skeemas
Comprehensive JSON Schema (drafts 3 and 4) validation.
Installation
npm install skeemas --save
Basic Validation
skeemas.validate(subject, schema[, options])
var skeemas = ; skeemasvalid; // trueskeemasvalid; // falseskeemasvalid; // true // Result contains an array of errorsvar result = skeemas;resultvalid; // falseresulterrors; // array with 2 error objects // Pass the "breakOnError" option to stop processing on the first errorvar result = skeemas;resultvalid; // falseresulterrors; // array with 1 error object var result = skeemas; resultvalid; // trueassert;
For more information about constructing schemas see http://json-schema.org/ or the wonderful guide at http://spacetelescope.github.io/understanding-json-schema/index.html
Adding Schemas
Skeemas supports validation by schema id and refrences between schemas via the $ref
property:
// Create an instance of a validatorvar validator = ; // Add schemas to the validatorvalidator; // Validate by uri/idvalidatorvalid; // true // Use a $ref reference in other schemasvalidatorvalid; // true
Related Modules
- skeemas-body-parser - json body parser middleware with schema validation
- skeemas-markdown-validation - simple testing of json blocks in your markdown documentation
Development
Our tests are running the JSON Schema test suite at https://github.com/json-schema/JSON-Schema-Test-Suite. Those tests are referenced as a submodule and therefore dev setup is a little non-standard.
# clone the repo # install dependencies from npm npm install # install the test suite git submodule initgit submodule update # run the tests npm test
Feature Status
- Full Validation (all errors)
- Quick Validation (first error)
- Instance cleaning
- Manual reference additions
- Validate by reference
- Missing reference resolution
- Custom format validation
- Custom attribute validation
- Plugins
- JSON-Schema draft 03 and 04 feature support
- Ignored schema attributes
- $schema
- title
- description
- default
- References
- id
- definitions
- $ref
- Validations by type
- any
- type
- enum
- extends
- allOf
- anyOf
- oneOf
- not
- disallow
- required
- format
- array
- items
- additionalItems
- minItems
- maxItems
- uniqueItems
- boolean
- null
- number, integer
- multipleOf
- divisibleBy
- minimum
- maximum
- exclusiveMinimum
- exclusiveMaximum
- object
- properties
- patternProperties
- additionalProperties
- required
- dependencies
- minProperties
- maxProperties
- dependencies
- string
- minLength
- maxLength
- pattern
- format
- date-time
- date
- time
- utc-millisec
- hostname
- host-name
- ip-address
- ipv4
- ipv6
- uri
- regex
- color
- style
- phone
- any
- Ignored schema attributes