I'm trying to compare parced JSON to JSON reference by following code:
const Ajv = require("ajv");
const parsedData = JSON.parse(fs.readFileSync(jsonDataPath, 'utf8'));
const parsedSchema = JSON.parse(fs.readFileSync(jsonSchemaPath, 'utf8'));
const ajvInstance = Ajv({ allErrors: true });
const valid = ajvInstance.validate(parsedSchema, parsedData);
if (valid) {
console.log("User data is valid");
} else {
console.log("User data is INVALID!");
console.log(ajv.errors);
}
and got following error:
Error: schema is invalid: data should be equal to constant
As you see, I've tried converting variables to const
, but it was no help.
You got this error because somewhere in your JSON schema you have a definition that field is 'const'. This error is not about your JavaScript code.
Read the documentation for examples and for more information const