Go to the documentation of this file.
3#include <nlohmann/json-schema.hpp>
10{
11 "$schema": "http://json-schema.org/draft-07/schema#",
12 "type": "object",
13 "properties": {
14 "myUri": {
15 "type":"string",
16 "format": "uri"
17 }
18 }
19})"_json;
22static json
good_uri = {{
"myUri",
"http://hostname.com/"}};
23static json
bad_uri = {{
"myUri",
"http:/hostname.com/"}};
27 if (format ==
"uri") {
28 if (value.find(
"://") == std::string::npos)
29 throw std::invalid_argument(
"URI does not contain :// - invalid");
31 throw std::logic_error(
"Don't know how to validate " + format);
40 }
catch (
const std::exception &e) {
41 std::cerr <<
"Validation of schema failed, here is why: " << e.what() <<
"\n";
49 }
catch (
const std::exception &e) {
50 std::cerr <<
"Validation expectedly failed, here is why: " << e.what() <<
"\n";
void set_root_schema(const json &)
json_validator(schema_loader=nullptr, format_checker=nullptr, content_checker=nullptr)
json validate(const json &) const