MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / optional_format_example

Function optional_format_example

examples/src/jsonschema_examples.cpp:489–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487}
488
489void optional_format_example()
490{
491 json schema = json::parse(R"(
492{
493 "$id": "/schema_str",
494 "$schema": "https://json-schema.org/draft/2020-12/schema",
495 "properties": {
496 "Date": {
497 "format": "date-time",
498 "type": "string"
499 }
500 },
501 "required": [
502 "Date"
503 ],
504 "type": "object",
505 "unevaluatedProperties": false
506}
507 )");
508
509 auto compiled = jsoncons::jsonschema::make_json_schema(schema,
510 jsonschema::evaluation_options{}.require_format_validation(true));
511
512 json data = json::parse(R"(
513{ "Date" : "2024-03-19T26:34:56Z" }
514 )");
515
516 jsoncons::json_decoder<ojson> decoder;
517 compiled.validate(data, decoder);
518 ojson output = decoder.get_result();
519 std::cout << pretty_print(output) << "\n";
520}
521
522void walk_example() // since 0.175.0
523{

Callers 1

mainFunction · 0.85

Calls 6

parseFunction · 0.85
make_json_schemaFunction · 0.85
pretty_printFunction · 0.85
get_resultMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected