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

Function cross_schema_example

examples/src/jsonschema_examples.cpp:455–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455void cross_schema_example()
456{
457 json schema = json::parse(R"(
458{
459 "$schema": "https://json-schema.org/draft/2020-12/schema",
460 "$id": "https://example.com/schema",
461 "$defs": {
462 "foo": {
463 "$schema": "http://json-schema.org/draft-07/schema#",
464 "$id": "schema/foo",
465 "definitions" : {
466 "bar" : {
467 "type" : "string"
468 }
469 }
470 }
471 },
472 "properties" : {
473 "thing" : {
474 "$ref" : "schema/foo#/definitions/bar"
475 }
476 }
477}
478)");
479 jsonschema::json_schema<json> compiled = jsonschema::make_json_schema(schema);
480
481 json data = json::parse(R"({"thing" : 10})");
482
483 jsoncons::json_decoder<ojson> decoder;
484 compiled.validate(data, decoder);
485 ojson output = decoder.get_result();
486 std::cout << pretty_print(output) << "\n\n";
487}
488
489void optional_format_example()
490{

Callers 1

mainFunction · 0.85

Calls 5

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