kazuho / picojson

a header-file-only, JSON parser serializer in C++
BSD 2-Clause "Simplified" License
1.12k stars 221 forks source link

Maintaining order of values when serializing. #54

Open Ender1618 opened 10 years ago

Ender1618 commented 10 years ago

Would it be possible to add support to maintain the original order of json object value entries, as they were specified int he original json that was parsed, when serializing a json DOM?

I have json object values ordered to be more comprehensible when input into the parser, but when I serialize the same DOM they come out in lexicographic order. I know this has to do with using std maps as json objects, since traversing those with the map iterator will yield a sorting by key, but it may be possible.

cdeil commented 10 years ago

:+1: to this feature request ... for my application I'd also much prefer to get a JSON object entries in the order in which I put them in. Not sure how to implement this though ... ?

kazuho commented 10 years ago

Sounds like a reasonable request to me.

What I would like to ask in turn is:

Once the two questions are met and if you do not want to maintain the altered version of picojson (as described in the second point), I will extend the type-traits mechanism (proposed in #52) to cover the object type as well and merge it to master.

cdeil commented 10 years ago

I don't know which container to use.

This stackoverflow post suggests using boost.multiindex. I don't have time to look at how this works and if something small can be bundled with picojson.

kazuho commented 10 years ago

This stackoverflow post suggests using boost.multiindex. I don't have time to look at how this works and if something small can be bundled with picojson.

Thank you for the info.

In this case, You do not need to worry about the size of the container implementation, since there is no need to bundle it with picojson. #52 is a proposal of providing a interface for the users to specify the value types at compile time.