npm install avsc
{
"type": "record",
"name": "Person",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "age", "type": "int" }
]
}
var avsc = require('avsc');
var personSchema = avsc.parse(fs.readFileSync('person.avsc'));
var jsonData = JSON.parse(fs.readFileSync('person.json'));
var validator = personSchema.createValidator();
var valid = validator(jsonData);
if (!valid) {
console.log('Validation errors:');
console.log(validator.errors);
} else {
console.log('Data is valid!');
}
This will output a list of any errors that occurred during validation, including information about the field or type that caused the error.
Asked: 2022-08-09 11:00:00 +0000
Seen: 7 times
Last updated: Feb 23 '22