JSON Parsing unexpected results with Array values of [7,7]

Hello, new Elixir developer here.

In a basic Elixir application created with ‘mix new name --sup’, I am attempting to parse a json response from an API call, I do not control the source of the api.

I noticed some unexpected results within an internal array that just contains the number sevens: [7,7,7,7]
Everything else in the large result appears fine, but I have not tackled that yet as I attempted to test this array of sevens in a smaller example:

JSON.decode("{\"key\": [6,6]}") 
{:ok, %{"key" => [6, 6]}}
iex(12)> JSON.decode("{\"key\": [6,7]}") 
{:ok, %{"key" => [6, 7]}}
iex(13)> JSON.decode("{\"key\": [7,7]}") 
{:ok, %{"key" => '\a\a'}}
iex(14)> JSON.decode("{\"key\": [7,6]}") 
{:ok, %{"key" => [7, 6]}}
iex(15)> JSON.decode("{\"key\": [7]}")  
{:ok, %{"key" => '\a'}}
iex(16)> JSON.decode("{\"key\": 7}")  
{:ok, %{"key" => 7}}

Then I tried the array parser directly.

JSON.Parser.Array.parse "[1, 2]"
{:ok, [1, 2], ""}
iex(3)> JSON.Parser.Array.parse "[7, 7]" 
{:ok, '\a\a', ""}
iex(4)> JSON.Parser.Array.parse "[6, 7]" 
{:ok, [6, 7], ""}
iex(5)> JSON.Parser.Array.parse "[7, 6]" 
{:ok, [7, 6], ""}
iex(7)> JSON.Parser.Array.parse "[7]"   
{:ok, '\a', ""}
iex(8)> JSON.Parser.Array.parse "[6]" 
{:ok, [6], ""}
iex(9)> JSON.Parser.Array.parse "[776]"
{:ok, [776], ""}
iex(10)> JSON.Parser.Array.parse "[77]" 
{:ok, 'M', ""}

My quick incomplete testing with Jason and Poison appears to have the same results.
I assume it is some character interpretation / conversion, but see no options for the JSON decoding functions.
Are there some system or project settings I need?

My tests are on a Macintosh:

Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Elixir 1.12.2 (compiled with Erlang/OTP 24)

Thanks! :smiley:

Thanks eksperimental
I should know by now, to not always trust your eyes and the output to console. New to Elixir, but long time developer.

iex(5)> {:ok, result, ""} = JSON.Parser.Array.parse("[7,7]")
{:ok, '\a\a', ""}
iex(6)> result
'\a\a'
iex(7)> Enum.sum(result)
14

We have all been hit by this one

1 Like