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

Function function_avg_example

examples/src/jsonpath_examples.cpp:167–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void function_avg_example()
168{
169 std::string data = R"(
170{
171"books":
172[
173 {
174 "title" : "A Wild Sheep Chase",
175 "author" : "Haruki Murakami",
176 "price" : 22.72
177 },
178 {
179 "title" : "The Night Watch",
180 "author" : "Sergei Lukyanenko",
181 "price" : 23.58
182 },
183 {
184 "title" : "The Comedians",
185 "author" : "Graham Greene",
186 "price" : 21.99
187 },
188 {
189 "title" : "The Night Watch",
190 "author" : "Phillips, David Atlee"
191 }
192]
193}
194 )";
195
196 auto j = jsoncons::json::parse(data);
197
198 // All titles whose price is greater than the average price
199 std::string expr = R"($.books[?(@.price > avg($.books[*].price))].title)";
200
201 jsoncons::json result = jsonpath::json_query(j, expr);
202 std::cout << result << "\n\n";
203}
204
205void function_floor_example()
206{

Callers 1

mainFunction · 0.85

Calls 2

parseFunction · 0.85
json_queryFunction · 0.85

Tested by

no test coverage detected