Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The library doesn't want to insert an unordered_map #1010

Closed
tristan957 opened this issue Mar 13, 2018 · 3 comments
Closed

The library doesn't want to insert an unordered_map #1010

tristan957 opened this issue Mar 13, 2018 · 3 comments
Labels
kind: question solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)

Comments

@tristan957
Copy link

Bug Report

  • What is the issue you have? I am trying to insert an unordered_map, but it always comes out ordered in the json file.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

args = {"hello", "world"};
json j;
// get info from file
j["distributions"].push_back(std::unordered_map<std::string, std::string>({{"name", args[1]}, {"location", args[2]}}));

{
    "distributions": [
        {
            "location": "world",
            "name": "hello"
        },
        {
            "location": "there",
            "name": "hi"
        },
        {
            "location": "partin",
            "name": "tristan"
        }
    ]
}
  • What is the expected behavior? I want the name key, then the location key.

  • And what is the actual behavior instead? The location key comes before the name key.

  • Which compiler and operating system are you using? Is it a supported compiler? G++ 7.3 Solus (Linux)

  • Did you use a released version of the library or the version from the develop branch? Released (latest stable)

@nlohmann
Copy link
Owner

The library uses std::map internally to store object keys, so they are always ordered. See https://github.com/nlohmann/json#notes (last item) for more information.

@nlohmann nlohmann added kind: question solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope) labels Mar 13, 2018
@tristan957
Copy link
Author

Thanks for the comment. I did not see that.

@nlohmann
Copy link
Owner

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)
Projects
None yet
Development

No branches or pull requests

2 participants