json-schema-validator

1.1.0 • Public • Published

json-schema-validator

Build Status

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

Readme

Keywords

none

Package Sidebar

Install

npm i json-schema-validator

Weekly Downloads

378

Version

1.1.0

License

MIT

Last publish

Collaborators

  • magomogo