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

can function dump() return string in the order I push in the json object ? #286

Closed
zyinter2008 opened this issue Jul 25, 2016 · 3 comments
Closed

Comments

@zyinter2008
Copy link

the program like this:
json obj = { {"result", "OK"}, {"model", "AAA" } };
string str = obj.dump();
which i want get { {"result", "OK"}, {"model", "AAA" } }, but it always return { {"model", "AAA" }, {"result", "OK"} }

@nlohmann
Copy link
Owner

This is not possible. JSON objects are, by definition, unordered set of key-value pairs. In the library, I use a std::map to store objects, so the keys are always ordered alphabetically. You may want to try if you use https://github.com/nlohmann/fifo_map as object_t.

@ivakyb
Copy link

ivakyb commented Jan 12, 2018

How to replace std::map with fifo_map?

@ivakyb
Copy link

ivakyb commented Jan 15, 2018

See https://github.com/nlohmann/json#notes, last item about insertion order of object elements.

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

3 participants