[英]> Error: schema is invalid: data should be equal to constant in ajv JSON Schema
I'm trying to compare parced JSON to JSON reference by following code:我正在尝试通过以下代码将 parced JSON 与 JSON 参考进行比较:
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.如您所见,我尝试将变量转换为
const
,但没有帮助。
You got this error because somewhere in your JSON schema you have a definition that field is 'const'.您收到此错误是因为在您的 JSON 模式中的某个地方定义了该字段为“const”。 This error is not about your JavaScript code.
此错误与您的 JavaScript 代码无关。
The const keyword is used to restrict a value to a single value.
const 关键字用于将值限制为单个值。
Read the documentation for examples and for more information const阅读文档以获取示例和更多信息const
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.