Ajv - the fastest JSON-schema validator

node v0.12.18
version: 1.4.5
endpointsharetweet
var Ajv = require('ajv'); var ajv = Ajv({allErrors: true}); var validate = ajv.compile({ "properties": { "foo": { "type": "string" }, "bar": { "type": "number", "maximum": 3 } } }); test({"foo": "abc", "bar": 2}); test({"foo": 2, "bar": 4}); function test(data) { var valid = validate(data); if (valid) console.log('Valid!'); else console.log('Invalid:', ajv.errorsText(validate.errors)); }
Loading…

no comments

    sign in to comment