I have a sample nlohmann json object here. I would like to replace all the "onClick" to the "Click". please bear in mind that this a sample only. The object contains many json arrays inside each other.
{
"menu": {
"id": "file",
"name": "File",
"popup": {
"menuitem": [
{
"name": "New",
"onclick": "CreateDoc()"
},
{
"name": "Open",
"onclick": "OpenDoc()"
},
{
"name": "Save",
"onclick": "SaveDoc()"
},
{
"toy": [
{
"value": "toyA",
"onclick": "CreateDoc()"
},
{
"value": "toyB",
"onclick": "OpenDoc()"
}
]
}
]
}
}
}
this is what I tried my self:
auto change_key = [](nlohmann::json &object, const std::string& old_key, const std::string& new_key)
{
json::iterator it = object.find(old_key);
while(it != object.end()){
std::swap(object[new_key], it.value());
object.erase(it);
it = object.find(old_key);
}
};