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

Function walk_example

examples/src/jsonschema_examples.cpp:522–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520}
521
522void walk_example() // since 0.175.0
523{
524 std::string schema_str = R"(
525{
526 "$id": "https://example.com/arrays.schema.json",
527 "$schema": "https://json-schema.org/draft/2020-12/schema",
528 "description": "Arrays of strings and objects",
529 "type": "object",
530 "properties": {
531 "fruits": {
532 "type": "array",
533 "items": {
534 "type": "string"
535 }
536 },
537 "vegetables": {
538 "type": "array",
539 "items": {
540 "$ref": "#/$defs/veggie"
541 }
542 }
543 },
544 "$defs": {
545 "veggie": {
546 "type": "object",
547 "required": [
548 "veggieName",
549 "veggieLike"
550 ],
551 "properties": {
552 "veggieName": {
553 "type": "string",
554 "description": "The name of the vegetable."
555 },
556 "veggieLike": {
557 "type": "boolean",
558 "description": "Do I like this vegetable?"
559 }
560 }
561 }
562 }
563}
564 )";
565
566 auto schema = jsoncons::ojson::parse(schema_str);
567 auto compiled = jsonschema::make_json_schema(std::move(schema));
568
569 std::string data_str = R"(
570{
571 "fruits": [
572 "apple",
573 "orange",
574 "pear"
575 ],
576 "vegetables": [
577 {
578 "veggieName": "potato",
579 "veggieLike": true

Callers 1

mainFunction · 0.85

Calls 8

parseFunction · 0.85
make_json_schemaFunction · 0.85
is_objectMethod · 0.45
findMethod · 0.45
endMethod · 0.45
stringMethod · 0.45
valueMethod · 0.45
walkMethod · 0.45

Tested by

no test coverage detected