michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.6k stars 170 forks source link

Arrays aren't decoded #131

Closed lpender closed 3 years ago

lpender commented 3 years ago

Hi! Thanks for your great library.

Here's what I'm working with in Elixir:

point = "{\"type\":\"Point\",\"coordinates\":[10,10]}"
Jason.decode!(point)
# %{"coordinates" => '\n\n', "type" => "Point"}

As you can see, the coordinates are lost.

Here's what happens when I do something similar in JS

const point = "{\"type\":\"Point\",\"coordinates\":[10,10]}"
JSON.parse(point)
# {"coordinates" => [10,10], "type" => "Point"}

Tried with Jason 1.0, 1.2

michalmuskala commented 3 years ago

This is a behaviour of Elixir in general, and is related to how things are printed in the shell. In particular in Elixir [10, 10] === '\n\n' - those are two ways of representing exactly the same value. Elixir, by default, prints lists of integers in printable range as charlists.

See more here: https://github.com/elixir-lang/elixir/wiki/FAQ#4-why-is-my-list-of-integers-printed-as-a-string

lpender commented 3 years ago

Thanks

On Wed, Mar 3, 2021 at 10:24 AM Michał Muskała notifications@github.com wrote:

Closed #131 https://github.com/michalmuskala/jason/issues/131.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/michalmuskala/jason/issues/131#event-4403624231, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKXMWUEUI2RWYSV53EF7VDTBZ5GBANCNFSM4YRW3ZGA .