RunKit + npm: ajv

node v8.17.0
endpointsharetweet
var Ajv = require('ajv'); var ajv = new Ajv({allErrors: true, jsonPointers: true}); var schema = { "type": "object", "properties": { "root": { "type": "object", "patternProperties": { "^[a-zA-Z0-9_]+quot;: { "oneOf": [ {"enum": ["a"]}, {"enum": ["b"]}, {"$ref": "#/cde"} ] } } } }, "cde": { "anyOf": [ {"enum": ["c"]}, {"enum": ["d"]}, {"enum": ["e"]} ] } }; var validate = ajv.compile(schema); test({ "root": { "zoo": "f" } }); function test(data) { var valid = validate(data); if (valid) console.log('Valid!'); else console.log('Invalid!',validate.errors); }
Created from: https://npm.runkit.com/ajv
Loading…