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

Function remove_selected_books

examples/src/jsonpath_location_examples.cpp:20–71  ·  view source on GitHub ↗

since 0.172.0

Source from the content-addressed store, hash-verified

18
19// since 0.172.0
20void remove_selected_books()
21{
22 std::string json_string = R"(
23{
24 "books":
25 [
26 {
27 "category": "fiction",
28 "title" : "A Wild Sheep Chase",
29 "author" : "Haruki Murakami",
30 "price" : 22.72
31 },
32 {
33 "category": "fiction",
34 "title" : "The Night Watch",
35 "author" : "Sergei Lukyanenko",
36 "price" : 23.58
37 },
38 {
39 "category": "fiction",
40 "title" : "The Comedians",
41 "author" : "Graham Greene",
42 "price" : 21.99
43 },
44 {
45 "category": "memoir",
46 "title" : "The Night Watch",
47 "author" : "Phillips, David Atlee"
48 }
49 ]
50}
51 )";
52
53 json doc = json::parse(json_string);
54
55 auto expr = jsonpath::make_expression<json>("$.books[?(@.category == 'fiction')]");
56 std::vector<jsonpath::json_location> locations = expr.select_paths(doc,
57 jsonpath::result_options::sort_descending | jsonpath::result_options::sort_descending);
58
59 for (const auto& location : locations)
60 {
61 std::cout << jsonpath::to_string(location) << "\n";
62 }
63 std::cout << "\n";
64
65 for (const auto& location : locations)
66 {
67 jsonpath::remove(doc, location);
68 }
69
70 std::cout << jsoncons::pretty_print(doc) << "\n\n";
71}
72
73// since 0.172.0
74void remove_selected_books_in_one_step()

Callers 1

mainFunction · 0.85

Calls 5

parseFunction · 0.85
pretty_printFunction · 0.85
select_pathsMethod · 0.80
to_stringFunction · 0.50
removeFunction · 0.50

Tested by

no test coverage detected