SchemaInspector.validate()

Validate some json data against a schema.

Schema-Inspector is a powerful tool to sanitize and validate JS objects. It's designed to work both client-side and server-side and to be scalable with allowing asynchronous and synchronous calls.

Usage

Hover over inputs/exits for more info.

var SchemaInspector = require('machinepack-schemainspector');


// Validate some json data against a schema.

SchemaInspector.validate({

schema: {},

data: '*',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Provided data and schema are not compatible.

invalid: function (result) {

 

},

// OK.

success: function () {

 

},

});

Inputs

schema required

The JSON-schema to validate against

{}
data required

The data to validate (i.e. the "JSON instance")

'*'

Exits

error

An unexpected error occurred.

invalid

Provided data and schema are not compatible.

'Property @.type: must be equal to "email", but is equal to "sms"                Property @.to[0]: must be a string, but is number                Property @.dolor[4]: must match [email], but is equal to "test"'
success

OK.