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

Encoding a map changes the order of the keys #21

Closed
sideshow opened this Issue Dec 14, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@sideshow

sideshow commented Dec 14, 2014

Encoding a map changes the order of the keys;

iex(6)> Poison.encode %{a: 1, b: 2, c: 3}
{:ok, "{\"c\":3,\"b\":2,\"a\":1}"} # reversed keys

Similarly decoding json changes the order of the keys;

iex(7)> Poison.decode "{\"c\":3,\"b\":2,\"a\":1}", keys: :atoms!
{:ok, %{a: 1, b: 2, c: 3}} # reversed keys
@devinus

This comment has been minimized.

Owner

devinus commented Dec 14, 2014

@sideshow A map's keys are unordered. Their order is not guaranteed in Erlang or JavaScript.

@devinus devinus closed this Dec 14, 2014

@dvv

This comment has been minimized.

dvv commented Jul 30, 2017

Still, by substituting foldlwith foldrat both https://github.com/devinus/poison/blob/master/lib/poison/encoder.ex#L249 and https://github.com/devinus/poison/blob/master/lib/poison/encoder.ex#L255 solves reversal of keys while encoding.
Is such PR welcome?

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