UNPKG

bs-ajv

Version:

BucklesScript bindings to Ajv (Another JSON Validator)

32 lines (29 loc) 587 B
/* just an exercise to see what the interface to Ajv is like */ const Ajv = require('ajv'); const ajv = new Ajv({ jsonPointers: true }); const validate_me = { "mess~ages": [ "Hello world!", "Goodbye cruel world!", "HI" ]}; const schema = { title: "Message", type: "object", properties: { "mess~ages": { type: "array", contains: { type: "number" } } }, required: [ "mess~ages" ] }; const validate = ajv.compile(schema); const valid = validate(validate_me); console.log('valid=', valid); console.log('errors=', validate.errors);