I have been using the nlohmann json library for a while, but i found myself with a problem recently. I have a vector of indexes for an object:
vector<string> indexes = {"value1", "subval"}; // etc
and I want to do something like this:
json myObj = "{\"value1\":{}}"_json;
myObj["value1"]["subval"] = "test";
How can i do this?
I tried this:
json myObj = "{\"value1\":{}}"_json;
json ref = myObj;
for (string i : indexes) {
ref = ref[i];
}
myObj = ref;
but this will not work because it is not accessing nested elements, it is just setting the object to be the nested value.