-
Hi everyone, When I try to validate my json file against my json.schema, I get the following error: "validation failed for additional property '$id': instance invalid as per false-schema" However, $id is a reserved property according to the json schema. See here: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01#section-9.2 How do I make the validator ignore the reserved property '$id' or handle it correctly? Please find my json and my json.schema here: Thanks for the help and best regards. P.S.: My code looks like this: char* jsonFilePath = "PathToFile";
char* jsonSchemaPath = "PathToSchema";
BOOL validationResult;
char cValidationErrors[4096];
unsigned int uiLenValErrors = sizeof(cValidationErrors);
ifstream jsonFileStream(jsonFilePath);
ifstream jsonSchemaStream(jsonSchemaPath);
json myJson = json::parse(jsonFileStream);
json myJsonSchema = json::parse(jsonSchemaStream);
json_validator validator; // create validator
validationResult = TRUE;
try {
validator.set_root_schema(myJsonSchema); // insert root-schema
}
catch (const std::exception& e) {
std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n";
return EXIT_FAILURE;
}
/* json-parse the people - API of 1.0.0, default throwing error handler */
for (auto& person : { myJson }) {
std::cout << "About to validate this person:\n"
<< std::setw(2) << person << std::endl;
try {
validator.validate(person); // validate the document - uses the default throwing error-handler
std::cout << "Validation succeeded\n";
}
catch (const std::exception& e) {
//std::cerr << "Validation failed, here is why: " << e.what() << "\n";
sprintf_s(cValidationErrors, uiLenValErrors, "Validation for '%s' failed due to: %s\n", person.type_name(), e.what());
validationResult = FALSE;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
is a segfaut, so obviously this is not the code you're running. |
Beta Was this translation helpful? Give feedback.
-
In your schema in every object you have "additionalProperties": false, So any field mentioned in the json-file which not described by the schema will make validation fail. Hence the
|
Beta Was this translation helpful? Give feedback.
In your schema in every object you have
So any field mentioned in the json-file which not described by the schema will make validation fail. Hence the
"validation failed for additional property '$id': instance invalid as per false-schema"
.$id
and other reserved words are reserved for schemas only, but not for documents. You can of course use any name you want, but the schema has to accept them.