Skip to content
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

Maintaining order of values when serializing. #54

Open
Ender1618 opened this issue Nov 13, 2014 · 4 comments
Open

Maintaining order of values when serializing. #54

Ender1618 opened this issue Nov 13, 2014 · 4 comments

Comments

@Ender1618
Copy link

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
Copy link

cdeil commented Nov 13, 2014

👍 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
Copy link
Owner

kazuho commented Nov 13, 2014

Sounds like a reasonable request to me.

What I would like to ask in turn is:

  • do you know an associative container that fits your need (that remembers the order in which the key-value pairs were added)?
  • would you mind checking if the container works fine with picojson, by changing the type of picojson::value::object (defined in line 112) to the container?

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
Copy link

cdeil commented Nov 13, 2014

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
Copy link
Owner

kazuho commented Nov 14, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants