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

Function function_keys_example

examples/src/jsonpath_examples.cpp:256–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void function_keys_example()
257{
258 std::string data = R"(
259{
260"books":
261[
262 {
263 "title" : "A Wild Sheep Chase",
264 "author" : "Haruki Murakami",
265 "price" : 22.72
266 },
267 {
268 "title" : "The Night Watch",
269 "author" : "Sergei Lukyanenko",
270 "price" : 23.58
271 },
272 {
273 "title" : "The Comedians",
274 "author" : "Graham Greene",
275 "price" : 21.99
276 },
277 {
278 "title" : "The Night Watch",
279 "author" : "Phillips, David Atlee"
280 }
281]
282}
283 )";
284
285 auto j = jsoncons::json::parse(data);
286
287 // All books that don't have a price
288 std::string expr = "$.books[?(!contains(keys(@),'price'))]";
289
290 jsoncons::json result = jsonpath::json_query(j, expr);
291 std::cout << result << "\n\n";
292}
293
294void function_length_example()
295{

Callers 1

mainFunction · 0.85

Calls 2

parseFunction · 0.85
json_queryFunction · 0.85

Tested by

no test coverage detected