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

Hi, is there any method to dump json to string with the insert order rather than alphabets #356

Closed
ZhaoGuangYue1986 opened this issue Nov 8, 2016 · 1 comment

Comments

@ZhaoGuangYue1986
Copy link

Hi, is there any method to dump json to string with the insert order rather than alphabets

@nlohmann
Copy link
Owner

nlohmann commented Nov 8, 2016

No, this is not possible with the default parameters:

The order name/value pairs are added to the object is not preserved by the library. Therefore, iterating an object may return name/value pairs in a different order than they were originally stored. In fact, keys will be traversed in alphabetical order as std::map with std::less is used by default. Please note this behavior conforms to RFC 7159, because any order implements the specified "unordered" nature of JSON objects.

You would need to pass a version of map without alphabetical order to the library.

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

No branches or pull requests

2 participants