AJV uniqueItems Objects

node v10.23.1
version: master
endpointsharetweet
var Ajv = require('ajv'); var ajv = new Ajv({allErrors: true}); var schema = { "type": "array", "uniqueItems": true, "items": { "type": "object", "properties": { "a": { "type": "string", }, "b": { "type": "string" } } } } var validate = ajv.compile(schema); test([ { "a": "1", "b": "2" }, { "b": "2", "a": "1" } ]); function test(data) { var valid = validate(data); if (valid) console.log('Valid!'); else console.log('Invalid: ' + ajv.errorsText(validate.errors)); }
Created from: https://npm.runkit.com/ajv
Loading…

no comments

    sign in to comment