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

Json.Decode.keyValuePairs does not keep field order #940

Closed
jinjor opened this Issue Feb 8, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@jinjor
Contributor

jinjor commented Feb 8, 2018

It looks Json.Decode.keyValuePairs returns fields in reversed order. I expect it keeps the order as they are defined.

> import Json.Decode as D
> import Json.Encode as E

> D.decodeString (D.keyValuePairs D.int) "{\"a\":1,\"b\":2}"
Ok [("b",2),("a",1)] : Result.Result String (List ( String, Int ))

> D.decodeString (D.keyValuePairs D.int) "{\"b\":1,\"a\":2}"
Ok [("a",2),("b",1)] : Result.Result String (List ( String, Int ))

> D.decodeString (D.keyValuePairs D.int) "{\"a\":1,\"b\":2, \"c\":3}"
Ok [("c",3),("b",2),("a",1)] : Result.Result String (List ( String, Int ))

> D.decodeValue (D.keyValuePairs D.int) (E.object [("a", E.int 1), ("b", E.int 2)])
Ok [("b",2),("a",1)] : Result.Result String (List ( String, Int ))

> D.decodeValue (D.keyValuePairs D.int) (E.object [("b", E.int 1), ("a", E.int 2)])
Ok [("a",2),("b",1)] : Result.Result String (List ( String, Int ))

I confirmed JavaScript works as I expected.

> Object.keys({a:1, b:2})
[ 'a', 'b' ]

> Object.keys({b:1, a:2})
[ 'b', 'a' ]

> Object.keys(JSON.parse('{"a":1, "b":2}')) 
[ 'a', 'b' ]

> Object.keys(JSON.parse('{"b":1, "a":2}')) 
[ 'b', 'a' ]

Elm: 0.18.0
elm-lang/core: 5.1.1
OS: macOS

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Feb 8, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Feb 8, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@jinjor jinjor closed this Feb 8, 2018

@jinjor

This comment has been minimized.

Show comment
Hide comment
@jinjor

jinjor Feb 8, 2018

Contributor

Oops, I found the correct spec is written here.

An object is an unordered collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array.

Contributor

jinjor commented Feb 8, 2018

Oops, I found the correct spec is written here.

An object is an unordered collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array.

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