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:
var Ajv = require("ajv");
var ajv = new Ajv();
require("ajv-data-table")(ajv)
valiate = ajv.compile({
"$schema": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#",
"data-table": {
properties:{
"foo":{type:'number'},
"bar":{type:'string'},
"bat":{type:'string',format:'email'},
},
required:[
"foo",
"bar",
],
patternProperties:{
"^@[a-z]+$":{
type:"object",
properties:{
name:{type:"string"},
time:{
type:"string",
format:"date",
}
},
}
}
}
})
Matching Examples
{
"foo":[1],
"bar":["Hello"],
"bat":["hello@world.com"],
}
{
"foo":[1,2],
"bar":["Hello","Foo"],
"bat":["hello@world.com","foo@bar.com"],
}
{
"foo":[],
"bar":[],
"bat":[],
}
{
"foo":[],
"bar":[],
}
{
"foo":[1],
"bar":['hi'],
"@foo":[{name:"foo",time:"2016-01-01"}],
}
Failing Examples
{
"foo":[1,2],
"bar":["Hello"],
"bat":["Oscar@madison.com"],
}
{
"foo":[1],
"bar":[],
"bat":[],
}
{
"foo":[1,2],
"bar":["Hello","Oscar"],
"bat":["world","madison"],
}
{
"foo":[],
"bat":[],
}
{
"foo":[1],
"bar":['hi'],
"@foo":[{name:"foo",time:"yesterday afternoon"}],
}