update.cpp 415 B

123456789101112131415161718
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <nlohmann/json.hpp>
  4. using json = nlohmann::json;
  5. int main()
  6. {
  7. // create two JSON objects
  8. json o1 = R"( {"color": "red", "price": 17.99} )"_json;
  9. json o2 = R"( {"color": "blue", "speed": 100} )"_json;
  10. // add all keys from o2 to o1 (updating "color")
  11. o1.update(o2);
  12. // output updated object o1
  13. std::cout << std::setw(2) << o1 << '\n';
  14. }