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

Function walk_example2

examples/src/jsonschema_examples.cpp:612–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612void walk_example2() // since 1.7.0
613{
614 std::string schema_str = R"(
615{
616 "$id": "https://example.com/arrays.schema.json",
617 "$schema": "https://json-schema.org/draft/2020-12/schema",
618 "description": "Arrays of strings and objects",
619 "type": "object",
620 "properties": {
621 "fruits": {
622 "type": "array",
623 "items": {
624 "type": "string"
625 }
626 },
627 "vegetables": {
628 "type": "array",
629 "items": {
630 "$ref": "#/$defs/veggie"
631 }
632 }
633 },
634 "$defs": {
635 "veggie": {
636 "type": "object",
637 "required": [
638 "veggieName",
639 "veggieLike"
640 ],
641 "properties": {
642 "veggieName": {
643 "type": "string",
644 "description": "The name of the vegetable."
645 },
646 "veggieLike": {
647 "type": "boolean",
648 "description": "Do I like this vegetable?"
649 }
650 }
651 }
652 }
653}
654 )";
655
656 auto schema = jsoncons::ojson::parse(schema_str);
657 auto compiled = jsonschema::make_json_schema(std::move(schema));
658
659 std::string data_str = R"(
660{
661 "fruits": [
662 "apple",
663 "orange",
664 "pear"
665 ],
666 "vegetables": [
667 {
668 "veggieName": "potato",
669 "veggieLike": true

Callers 1

mainFunction · 0.85

Calls 7

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

Tested by

no test coverage detected