50{
51
52
54
55 try {
57 } catch (const std::exception &e) {
58 std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n";
59 return EXIT_FAILURE;
60 }
61
62
63
65 std::cout << "About to validate this person:\n"
66 << std::setw(2) << person << std::endl;
67 try {
68 auto defaultPatch =
validator.validate(person);
69 std::cout << "Validation succeeded\n";
70 std::cout << "Patch with defaults: " << defaultPatch.dump(2) << std::endl;
71 } catch (const std::exception &e) {
72 std::cerr << "Validation failed, here is why: " << e.what() << "\n";
73 }
74 }
75
76
78 {
79 void error(
const nlohmann::json::json_pointer &ptr,
const json &
instance,
const std::string &message)
override
80 {
82 std::cerr <<
"ERROR: '" << ptr <<
"' - '" <<
instance <<
"': " << message <<
"\n";
83 }
84 };
85
87 std::cout << "About to validate this person:\n"
88 << std::setw(2) << person << std::endl;
89
92
93 if (err)
94 std::cerr << "Validation failed\n";
95 else
96 std::cout << "Validation succeeded\n";
97 }
98
99 return EXIT_SUCCESS;
100}
nlohmann::json_schema::json_validator validator
void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override
void error(const json::json_pointer &, const json &, const std::string &) override
static const auto instance
static json person_schema
static json good_defaulted_person