Skip to content

dynamically constructing an arbitrarily nested object #114

Description

@zcourts

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions