UNPKG

bs-ajv

Version:

BucklesScript bindings to Ajv (Another JSON Validator)

24 lines (22 loc) 531 B
/* just an exercise to see what the interface to Ajv is like */ const Ajv = require('ajv'); const ajv = new Ajv; const validate_me = { "alist": [ "foo", "bar", "baz" ] }; const schema = { title: "Root document", type: "object", properties: { alist: { title: "a list", type: "array", maxItems: 2, items: { type: "string", } } } }; const validate = ajv.compile(schema); const valid = validate(validate_me); console.log('valid=', valid); console.log('errors=', validate.errors);