bs-ajv
Version:
BucklesScript bindings to Ajv (Another JSON Validator)
29 lines (27 loc) • 555 B
JavaScript
/* just an exercise to see what the interface to Ajv is like */
const Ajv = require('ajv');
const ajv = new Ajv;
const validate_me = { "messages": [
"Hello world!",
"Goodbye cruel world!",
"HI"
]};
const schema = {
title: "Message",
type: "object",
properties: {
messages: {
type: "array",
contains: {
type: "number"
}
}
},
required: [
"messages"
]
};
const validate = ajv.compile(schema);
const valid = validate(validate_me);
console.log('valid=', valid);
console.log('errors=', validate.errors);