json-schema-validator/example/cmake-submodule/validate.cpp
2021-03-09 11:22:30 +01:00

21 lines
425 B
C++

#include <nlohmann/json-schema.hpp>
#include <iostream>
int main(void)
{
nlohmann::json schema_json{{"type", "number"}};
nlohmann::json_schema::json_validator validator;
validator.set_root_schema(schema_json);
validator.validate(1);
try {
validator.validate("\"1\"");
} catch (const std::exception &e) {
std::cerr << "expected exception: " << e.what() << "\n";
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}