michalmuskala / jason

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

Problem decoding a array with value "[88]", returns "X" #142

Closed rmoretto closed 2 years ago

rmoretto commented 2 years ago

Hello all! First, thanks for the great library!

So, I'm decoding a json string that contains a key with a array of value [88].

When I decode the json I receive the following result:

$ iex -S mix
Erlang/OTP 24 [erts-12.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit]
Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> ~s({"test": [88]}) |> Jason.decode!()
%{"test" => 'X'}

Which makes sense, as the binary representation for the letter X is equal <<88>>:

iex(2)> IO.inspect("X", binaries: :as_binaries)
<<88>>
"X"

Searching the Jason docs I couldn't find any reference of this behavior.

Don't know if is relevant, but this behavior also occurs when I use the File.read! function to load a .json file.

My system:

OS: Ubuntu 20.04.3 LTS
Elixir: 1.12.2
Erlang/OTP: 24

Any help is greatly appreciated.

rmoretto commented 2 years ago

Well, I'm sorry for the noise.

I ran some more tests and only the print of the value that looks wrong, but the underling value is correct:

iex(9)> ~s({"test": [88]}) |> Jason.decode!() |> Map.get("test") == [88]
true

I will close the issue.