An AJV plugin for validating Objects whose attributes represent columns in a table, a common practice for representing tabular data.
This plugin adds a macro keyword "data-table" which is parameterized like
an object, and matches objects whose elements are arrays of a common length
with elements of the type described in the properties
attribute of the
schema.
Usage:
// Create an AJV instancevar Ajv = ;var ajv = ; // Load the `data-table` keyword onto the instanceajv // Create a data-table validatorvaliate = ajv
Matching Examples
// Object with arrays of a common length, and appropriate data types "foo":1 "bar":"Hello" "bat":"hello@world.com" "foo":12 "bar":"Hello""Foo" "bat":"hello@world.com""foo@bar.com" // Empty arrays are ok "foo": "bar": "bat": // optional properties (columns) are not required "foo": "bar": // additional properties are handled according to `additionalProperties`// and `patternProperties` from the schema "foo":1 "bar":'hi' "@foo":name:"foo"time:"2016-01-01"
Failing Examples
// inconsistent array length "foo":12 "bar":"Hello" "bat":"Oscar@madison.com" "foo":1 "bar": "bat": // invalid format string "foo":12 "bar":"Hello""Oscar" "bat":"world""madison" // fails `format:'email'` // missing required field "bar" "foo": "bat": // fails the `patternProperties` from the schema "foo":1 "bar":'hi' "@foo":name:"foo"time:"yesterday afternoon"