| 126 | } |
| 127 | |
| 128 | void function_sum_example() |
| 129 | { |
| 130 | std::string data = R"( |
| 131 | { |
| 132 | |
| 133 | "books": |
| 134 | [ |
| 135 | { |
| 136 | "title" : "A Wild Sheep Chase", |
| 137 | "author" : "Haruki Murakami", |
| 138 | "price" : 22.72 |
| 139 | }, |
| 140 | { |
| 141 | "title" : "The Night Watch", |
| 142 | "author" : "Sergei Lukyanenko", |
| 143 | "price" : 23.58 |
| 144 | }, |
| 145 | { |
| 146 | "title" : "The Comedians", |
| 147 | "author" : "Graham Greene", |
| 148 | "price" : 21.99 |
| 149 | }, |
| 150 | { |
| 151 | "title" : "The Night Watch", |
| 152 | "author" : "Phillips, David Atlee" |
| 153 | } |
| 154 | ] |
| 155 | } |
| 156 | )"; |
| 157 | |
| 158 | auto j = jsoncons::json::parse(data); |
| 159 | |
| 160 | // All titles whose price is greater than the average price |
| 161 | std::string expr = R"($.books[?(@.price > sum($.books[*].price)/length($.books[*].price))].title)"; |
| 162 | |
| 163 | jsoncons::json result = jsonpath::json_query(j, expr); |
| 164 | std::cout << result << "\n\n"; |
| 165 | } |
| 166 | |
| 167 | void function_avg_example() |
| 168 | { |
no test coverage detected