Skip to content

can function dump() return string in the order I push in the json object ? #286

Closed

Description

@zyinter2008

the program like this:
json obj = { {"result", "OK"}, {"model", "AAA" } };
string str = obj.dump();
which i want get { {"result", "OK"}, {"model", "AAA" } }, but it always return { {"model", "AAA" }, {"result", "OK"} }

Activity

  1. nlohmann commented on Jul 25, 2016

    @nlohmann
    Owner

    This is not possible. JSON objects are, by definition, unordered set of key-value pairs. In the library, I use a std::map to store objects, so the keys are always ordered alphabetically. You may want to try if you use https://github.com/nlohmann/fifo_map as object_t.

  2. ivakyb commented on Jan 12, 2018

    @ivakyb

    How to replace std::map with fifo_map?

  3. ivakyb commented on Jan 15, 2018

    @ivakyb

    See https://github.com/nlohmann/json#notes, last item about insertion order of object elements.

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