You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why is an object ordering values by Alphabetical Order? #660
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.
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.
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.
Activity
nlohmann commentedon Jul 20, 2017
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.
nlohmann commentedon Jul 20, 2017
#106 #424
sqwunkly commentedon Sep 6, 2017
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
nlohmann commentedon Sep 6, 2017
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.
nlohmann commentedon Sep 6, 2017
(In the future, I shall mark issues regarding object orders as "won't fix" rather than pointing to fifo_map...)
nlohmann commentedon Jul 11, 2020
To be fixed with #2258.