Skip to content

Iteration weirdness #842

@Exaeta

Description

@Exaeta

Feature Request

It seems that right now iterating over a json object iterates over it as though it was an array, which is counter intuitive from the C++ perspective, which you would expect to be iterated like a std::map.

I suggest json::as_map() and json::as_array() so that one can do:

void foobar (nlohmann::json js1, nlohmann::json js2)
{
  for (auto & x : js2.as_map())
  {
    foo(x.first, x.second);
  }

  for (auto & x : js2.as_array())
  {
    bar(x);
  }
}

Both would return proxy objects (objects that contain a reference to the original, and different begin() and end() functions.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions