Install
npm i json-struct --save
Example
const Schema = require('json-struct');
const test = {
one: 'one',
two: {
two: 'two',
three: {
four: 4
},
four: {
five: 5
}
}
};
const schema = {
one: {
'value is one': v => {
return v == 'one';
}
},
two: {
three: {
'value is two': v => {
return v == 'two';
},
'is rigth length': v => {
return v.length == 3;
}
},
four: {
five: {
'is a number': v => {
return typeof v == 'number';
}
}
},
five: {
five: {
'is greater than 4': v => {
return v > 4;
}
}
}
}
}
const schema = new Schema(schema);
const result = schema.validate(test);