@aboveyou00/json-schema-validator
JSON schema validator
Last updated 3 years ago by aboveyou00 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @aboveyou00/json-schema-validator 
SYNC missed versions from official npm registry.

Build Status

@aboveyou00/json-schema-validator

This package uses the tv4 JSON Schema validator, and the formats provided by the tv4-formats. It loads all the referenced JSON schemas over the internet to bootstrap tv4.

Usage

Validator.simple('http://json-schema.org/geo', function (error, v) {
    assert.ifError(error);

    assert(v.validate(
        {latitude: 53.0, longitude: 43.0},
        'http://json-schema.org/geo'
    ).valid);

    done();
});

CLI

echo '{"json": "to validate"}' | json-validate http://some.type.id/

API

Constructor:

v = new Validator(schemaUris);

schemaUris: array of schema Uris to load (can be a string in the case of single URI)

--

v.fetchSchemas(schemaLoader, callback)

Load schemas over the net with schemaLoader(url, callback) and add to tv4 validator. All URI-s to be loaded: given in constructor and referenced by "$ref" clause in each loaded schema. Circular references get resolved.

--

v.validate(json, typeId)

Do validation of json against schema defined by typeId

Possible type Ids are:

validate() returns the tv4 validation result object. It will throw an Error if the schema for the passed typeId has not been loaded (fetched).

--

Validator.simple(uris, callback)

Just a shortcut for getting validator bootstrapped using request as schema loader

Current Tags

  • 1.1.1                                ...           latest (3 years ago)

2 Versions

  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 9
Dependencies (4)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |