-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Why is an object ordering values by Alphabetical Order? #660
Comments
We do not preserve the insertion order of object elements. The JSON standard defines objects as "an unordered collection of zero or more name/value pairs". To this end, this library does not preserve insertion order of name/value pairs. (In fact, keys will be traversed in alphabetical order as std::map with std::less is used by default.) Note this behavior conforms to the standard, and we shall not change it to any other order. 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. |
Hi Niels, Thanks for your reply. I checked out #106 #424 & #660, unfortunately I'm not an very experienced programmer and I doubt I've the knowledge/expertise to get the fifo_map up and running myself. In #106 habemus-papadum tried to impliment the fifo_map but he seemed to run into significant problems and it appears he may not have resolved them, at least he didn't say so. He seems a lot more experienced than me. #424 and #660 also provide no guidance on how to implement the fifo_maps or another solution for outputting the json data in unsorted format. I'd appreciate if you could provide or point me to a working example for implementing the fifo_map using your json library, such that I can open existing json data, add objects, edit and delete and save the data in unsorted format in the same easy intuitive manner described in your examples, like this:- Sorry if my request is of a basic level. If you could help I'd be much grateful, I feel others would also like to see a working example of how to implement the fifo_map to output unsorted json. Greg |
Using fifo_map and the like should be as simple as replacing the template parameter for the objects. Unfortunately, this seems not to work as I expected, and I am currently not aware of a working example. |
(In the future, I shall mark issues regarding object orders as "won't fix" rather than pointing to fifo_map...) |
To be fixed with #2258. |
Hi I am experiencing some weird behaviour I cannot really get behind why it does the following.
Imagine you want to have following json object:
What I did was:
When I print this (
cout << j.dump<< endl;
) I get following output:The order is messed up, how come?
The text was updated successfully, but these errors were encountered: