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

Function draft_201212_example

examples/src/jsonschema_examples.cpp:366–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364#endif // JSONCONS_HAS_STD_VARIANT
365
366void draft_201212_example()
367{
368 json schema = json::parse(R"(
369{
370 "$schema": "https://json-schema.org/draft/2020-12/schema",
371 "$id": "https://test.json-schema.org/typical-dynamic-resolution/root",
372 "$ref": "list",
373 "$defs": {
374 "foo": {
375 "$dynamicAnchor": "items",
376 "type": "string"
377 },
378 "list": {
379 "$id": "list",
380 "type": "array",
381 "items": { "$dynamicRef": "#items" },
382 "$defs": {
383 "items": {
384 "$comment": "This is only needed to satisfy the bookending requirement",
385 "$dynamicAnchor": "items"
386 }
387 }
388 }
389 }
390}
391)");
392
393 jsonschema::json_schema<json> compiled = jsonschema::make_json_schema(schema);
394
395 json data = json::parse(R"(["foo", 42])");
396
397 jsoncons::json_decoder<ojson> decoder;
398 compiled.validate(data, decoder);
399 ojson output = decoder.get_result();
400 std::cout << pretty_print(output) << "\n\n";
401}
402
403void draft_201909_example()
404{

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