0.1.0 • Published 8 years ago

xp-validate-json v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Build Status dependencies Status devDependencies Status

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();

License

The MIT License