You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<iostream>
#include"json.hpp"using json = nlohmann::json;
voidchange_key(json &object, const std::string& old_key, const std::string& new_key)
{
// get iterator to old key; TODO: error handling if key is not present
json::iterator it = object.find(old_key);
// create null value for new key and swap value from old keystd::swap(object[new_key], it.value());
// delete value at old key (cheap, because the value is null after swap)
object.erase(it);
}
intmain()
{
json j;
j["foo"] = "value";
std::cout << j << std::endl;
change_key(j, "foo", "bar");
std::cout << j << std::endl;
}
I want to change key within a loop. Is it possible? How? For example, having a code:
How to rename
a.key()
? Looks like it's not described itself by documentation.The text was updated successfully, but these errors were encountered: