michalmuskala / jason

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

Argument error when decoding to atom keys #137

Closed 220kts closed 3 years ago

220kts commented 3 years ago

Still a newbie at Elixir so I'm sure this must be something simple I'm doing wrong but I can't seem to find any info or explanation. Trying to decode any JSON string to an Elixir map with string keys works fine but if I pass the :atoms or :atoms! option I get the below argument error.

If it helps I'm running Elixir on FreeBSD. Thanks for any info!

iex(5)> Jason.decode("{\"somekey\": \"somevalue\"}") {:ok, %{"somekey" => "somevalue"}}

iex(7)> Jason.decode("{\"somekey\": \"somevalue\"}", [ %{ keys: :atoms! } ])
** (ArgumentError) argument error (stdlib 3.8.2.4) :maps.from_list([%{keys: :atoms!}]) (elixir 1.10.4) lib/enum.ex:1276: Enum.into/2 (jason 1.2.2) lib/jason.ex:56: Jason.decode/2

220kts commented 3 years ago

Never mind, seems like my options format was causing the issue. The below works:

iex(7)> Jason.decode("{\"somekey\": \"somevalue\"}", %{ :keys => :atoms })
{:ok, %{somekey: "somevalue"}}