bs-ajv
Version:
BucklesScript bindings to Ajv (Another JSON Validator)
29 lines (28 loc) • 583 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!",
5
]};
const schema = {
"title": "Message",
"type": "object",
"properties": {
"messages": {
"type": "array",
maxItems: 3,
"items": {
"type": "string"
}
}
},
"required": [
"messages"
]
};
const validate = ajv.compile(schema);
const valid = validate(validate_me);
console.log('valid=', valid);
console.log('errors=', validate.errors);