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

Function json_replace_example4

examples/src/jsonpath_examples.cpp:387–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385}
386
387void json_replace_example4()
388{
389 std::ifstream is("./input/books.json");
390 auto data =jsoncons::json::parse(is);
391
392 auto f = [](const std::string& /*location*/, jsoncons::json& book)
393 {
394 if (book.at("category") == "memoir" && !book.contains("price"))
395 {
396 book.try_emplace("price",140.0);
397 }
398 };
399
400 jsonpath::json_replace(data, "$.books[*]", f);
401 std::cout << pretty_print(data) << "\n\n";
402}
403
404void jsonpath_complex_examples()
405{

Callers 1

mainFunction · 0.85

Calls 6

parseFunction · 0.85
json_replaceFunction · 0.85
pretty_printFunction · 0.85
atMethod · 0.80
containsMethod · 0.45
try_emplaceMethod · 0.45

Tested by

no test coverage detected