Alpha ordering of json keys #77
-
toajson outputs a json string alphabetically ordered by key -- opposed to the order a document was constructed. was this a particular design decision. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
When your document is stored in-memory as If you can avoid the intermediate step of creating a 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 the value is created. |
Beta Was this translation helpful? Give feedback.
-
ah. the map. of course. |
Beta Was this translation helpful? Give feedback.
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 astd::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 usetao::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…