UNPKG

bs-ajv

Version:

BucklesScript bindings to Ajv (Another JSON Validator)

26 lines (23 loc) 540 B
/* just an exercise to see what the interface to Ajv is like */ const Ajv = require('ajv'); const ajv = new Ajv; const validate_me = { foo: 10, bar: 10 }; const schema = { title: "Root document", type: "object", required: ["foo", "bar"], properties: { foo: { type: "number", maximum: 10, }, bar: { type: "number", exclusiveMaximum: 10 } } }; const validate = ajv.compile(schema); const valid = validate(validate_me); console.log('valid=', valid); console.log('errors=', validate.errors);