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

Head Elements Sorting #543

Closed
Kostya1 opened this issue Mar 31, 2017 · 2 comments · Fixed by #2258
Closed

Head Elements Sorting #543

Kostya1 opened this issue Mar 31, 2017 · 2 comments · Fixed by #2258
Assignees
Labels
kind: question release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@Kostya1
Copy link

Kostya1 commented Mar 31, 2017

I need to make a json from iarray. I'm doing it like you in your example

json j;

j["pi"] = 3.141;

j["happy"] = true;

So, result json in this example will be:

{
"happy": true,
"pi": 3.141
}

The keys are sorted alphabetically. But I need
But I want make json like this

{
"pi": 3.141,
"happy": true
}

How can I make the keys in the same order as I add them?

@nlohmann
Copy link
Owner

This is not directly possible.

From the README:

By default, the library does not preserve the insertion order of object elements. This is standards-compliant, as the JSON standard defines objects as "an unordered collection of zero or more name/value pairs". If you do want to preserve the insertion order, you can specialize the object type with containers like tsl::ordered_map or nlohmann::fifo_map.

@nlohmann
Copy link
Owner

To be fixed with #2258.

@nlohmann nlohmann reopened this Jul 11, 2020
@nlohmann nlohmann self-assigned this Jul 11, 2020
@nlohmann nlohmann added release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jul 11, 2020
@nlohmann nlohmann added this to the Release 3.8.1 milestone Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants