xp-validate-json
v0.1.0
Published
Validate json using ajv
Downloads
3
Readme
xp-validate-json
Validate json using ajv and allow to throws http errors if the validation fail.
Installation
npm install xp-validate-json
Usage
Validate and remove extra properties directly
var validateJson = require('xp-validate-json');
// validation rules, see ajv
var schema = {
additionalProperties: false,
required: ['p1'],
properties: {
p1: {
type: 'string'
}
}
};
// compile the schema
var validate = validateJson.compileJit(schema);
// validate and throw http 400 error if the schema is not correct;
validate({ p1: '123' }).throwErrorsIfAny();