Using JSON Schemas for Validation

node v8.17.0
version: 1.0.0
endpointsharetweet
This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
var Ajv = require('ajv'); var ajv = new Ajv(); var schema = { "properties": { "foo": { "type": "string" }, "bar": { "type": "number", "maximum": 3 } }, "required": [ "foo" ] }; console.log(ajv.validate(schema, { "foo": "hi", "bar": 2 })); // true console.log(ajv.validate(schema, { "foo": 2, "bar": 4 })); // false console.log(ajv.validate(schema, { "foo": "hi" })); // true console.log(ajv.validate(schema, { "bar": 2 })); // false
Loading…

no comments

    sign in to comment