Skip to content

Alpha ordering of json keys #77

Answered by ColinH
adrianboston asked this question in Q&A
Discussion options

You must be logged in to vote

When your document is stored in-memory as tao::json::value then there is no direct way to restore the insertion order of object members given that they are held in a std::map< std::string, tao::json::value > which sorts them by key.

If you can avoid the intermediate step of creating a tao::json::value, and directly generate JSON Events instead, you could use tao::json::events::to_string as they directly generate the output from the Events and don't care about order.

Otherwise I don't see any easy solution, you could add a custom base class to the values in the object, store the insertion order there, and somehow use it later, but that would probably be quite cumbersome depending on how th…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by d-frey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #77 on December 20, 2020 18:37.