Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

tuts+. JSON-schema validation, part1. items/additionalItems

node v0.12.18
version: 0.1.0
endpointsharetweet
var Ajv = require('ajv'); var ajv = Ajv({allErrors: true}); var schema = { "type": "array", "items": [ { "type": "integer" }, { "type": "string" } ] }; var validate = ajv.compile(schema); console.log(validate([1, "foo"])); console.log(validate([1, "foo", {"bar": "baz"}])); validate(["foo", "bar"]);
var schema = { "type": "array", "items": [ { "type": "integer" }, { "type": "string" } ], "additionalItems": false }; var validate = ajv.compile(schema); validate([1, "foo", 3]);
var schema = { "type": "array", "items": [ { "type": "integer" }, { "type": "string" } ], "additionalItems": { "type": "integer" } }; var validate = ajv.compile(schema); console.log(validate([1, "foo", 3])); console.log(validate([1, "foo", 3, 4])); validate([1, "foo", "bar"]);
Loading…

no comments

    sign in to comment