How would you go about constructing an arbitrarily nested object e.g. a.b.c.d for serialisation?
Something like the following comes to mind but doesn't work:
auto record(nlohmann::json({});
nlohmann::json field = record;
for (const auto &part:utils::spilt(name)) {
field = field[part].is_null() ? nlohmann::json({}) : field[part];
}
where split(...) returns a vector of components from a dot notation string.
I know I can do record["a"]["b"]["c"] but they keys or depth aren't known in advance.
How would you go about constructing an arbitrarily nested object e.g. a.b.c.d for serialisation?
Something like the following comes to mind but doesn't work:
where split(...) returns a vector of components from a dot notation string.
I know I can do
record["a"]["b"]["c"]but they keys or depth aren't known in advance.