since 0.172.0
| 18 | |
| 19 | // since 0.172.0 |
| 20 | void 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 |
| 74 | void remove_selected_books_in_one_step() |
no test coverage detected