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

Function parent_operator_example

examples/src/jsonpath_examples.cpp:727–756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

725}
726
727void parent_operator_example()
728{
729 std::string doc = R"(
730[
731 {
732 "author" : "Haruki Murakami",
733 "title": "A Wild Sheep Chase",
734 "reviews": [{"rating": 4, "reviewer": "Nan"}]
735 },
736 {
737 "author" : "Sergei Lukyanenko",
738 "title": "The Night Watch",
739 "reviews": [{"rating": 5, "reviewer": "Alan"},
740 {"rating": 3,"reviewer": "Anne"}]
741 },
742 {
743 "author" : "Graham Greene",
744 "title": "The Comedians",
745 "reviews": [{"rating": 4, "reviewer": "Lisa"},
746 {"rating": 5, "reviewer": "Robert"}]
747 }
748]
749 )";
750
751 jsoncons::json store = jsoncons::json::parse(doc);
752
753 std::string path = "$[*].reviews[?(@.rating == 5)]^^";
754 auto result = jsonpath::json_query(store, path);
755 std::cout << pretty_print(result) << "\n\n";
756}
757
758template <typename Json>
759class my_custom_functions : public jsonpath::custom_functions<Json>

Callers 1

mainFunction · 0.85

Calls 3

parseFunction · 0.85
json_queryFunction · 0.85
pretty_printFunction · 0.85

Tested by

no test coverage detected