proteus-validator
Proteus Validator is JSON Schema Validator which provides an interface for validating JSON objects against JSON Schema Draft 3. It runs both in a browser and on Node.js.
Usage
Prepare
Node.js
var validator = ;
browser
validate schema
var schema = type: 'integer' ; // synchronous callvar errors = validator; // asynchronous callvalidator;
validate json objects
var schema = type: 'integer' ;var instance = 1; // synchronous callvar errors = validator; // asynchronous callvalidator;
This also runs schema validation. If you are going to validate many times by the same schema, it is recommended to register schema by registSchema method.
regist schema
var schema = type: 'integer' ;var errors = validator; // to use registered schema, send registered schema name instead of schema itself.var errors = validator; // you can also unregist schemavalidator;
others
addValidation
You can create your own validation.
validator;validator;
createValidator
You can create new validator.
var newValidator = validator;
Features
Definitions
Value | JSON Schema Draft v3 | Proteus Validator | Comments |
---|---|---|---|
type | ✔ | ✔ | |
properties | ✔ | ✔ | |
patternProperties | ✔ | ||
additionalProperties | ✔ | ✔ | |
items | ✔ | ✔ | |
additionalItems | ✔ | ||
required | ✔ | ✔ | |
dependencies | ✔ | ||
minimum | ✔ | ✔ | |
maximum | ✔ | ✔ | |
exclusiveMinimum | ✔ | ✔ | |
exclusiveMaximum | ✔ | ✔ | |
minItems | ✔ | ✔ | |
maxItems | ✔ | ✔ | |
uniqueItems | ✔ | ||
pattern | ✔ | ✔ | |
minLength | ✔ | ✔ | |
maxLength | ✔ | ✔ | |
enum | ✔ | ✔ | |
default | ✔ | ||
title | ✔ | ✔ | |
description | ✔ | ✔ | |
format | ✔ | ✔ | |
divisibleBy | ✔ | ||
disallow | ✔ | ||
extends | ✔ | ||
id | ✔ | ||
$ref | ✔ | ||
$schema | ✔ |
Types
Value | JSON Schema Draft v3 | Proteus Validator | Comments |
---|---|---|---|
string | ✔ | ✔ | |
number | ✔ | ✔ | |
integer | ✔ | ✔ | |
boolean | ✔ | ✔ | |
null | ✔ | ✔ | |
any | ✔ | ✔ | |
object | ✔ | ✔ | |
array | ✔ | ✔ | |
Union Types | ✔ |
String Formats
Value | JSON Schema Draft v3 | Proteus Validator | Comments |
---|---|---|---|
date-time | ✔ | ✔ | |
date | ✔ | ✔ | |
time | ✔ | ✔ | |
utc-millisec | ✔ | ✔ | |
regex | ✔ | ✔ | |
color | ✔ | ✔ | |
style | ✔ | ✔ | |
phone | ✔ | any string is allowed | |
uri | ✔ | ✔ | |
✔ | ✔ | ||
ip-address | ✔ | ✔ | |
ipv6 | ✔ | any string is allowed | |
host-name | ✔ | ✔ |