assert-my-json-valid

1.0.2 • Public • Published

assert-my-json-valid Build Status

Use is-my-json-valid to validate, throw if error

Install

$ npm install --save assert-my-json-valid

Usage

var assertMyJsonValid = require('assert-my-json-valid')
 
var schema = {
  type: 'string'
}
 
try {
  assertMyJsonValid(schema, 1)
} catch (e) {
  console.log(e) // => 'string data is the wrong type (value: 1)'
}
 
assertMyJsonValid(schema, 'foo') // no error

API

assertMyJsonValid(schema, value) -> output

Validates value against schema and throws a ValidationError if not valid.

It will only create a JSON validator once for each schema reference.

License

MIT © Andrew Joslin

Package Sidebar

Install

npm i assert-my-json-valid

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • andytjoslin