swap__object_t.cpp 494 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create a JSON value
  7. json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
  8. // create an object_t
  9. json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
  10. // swap the object stored in the JSON value
  11. value["translation"].swap(object);
  12. // output the values
  13. std::cout << "value = " << value << '\n';
  14. std::cout << "object = " << object << '\n';
  15. }