Closed everettvody closed 4 years ago
They don't get quoted to json strings, they get converted to json (which is a string itself. To see the actual output pipe the output of Jason.encode!/1
to IO.puts()
like:
iex(21)> Jason.encode!(123) |> IO.puts()
123
:ok
iex(22)> Jason.encode!(4.5) |> IO.puts()
4.5
:ok
iex(23)> Jason.encode!(true) |> IO.puts()
true
:ok
Those other issues are entirely unrelated.
I.E. you are not seeing them as json strings, you are seeing them as elixir values, which get pretty-printed as string in the console. Actually print it to see how it actually looks.
As noted above the behaviour is correct. The values are converted to JSON, which is a string in itself. If they were quoted in JSON they would look, for example, like "\"123\""
.
Sorry to bother you guys -- I shouldn't have trusted the iex output. I didn't think to pipe it through IO.puts
-- thanks for the explanation!
While using the encode function, I noticed that is apparently converting all its output to a string. I don't believe this is technically correct, as JSON supports a handful of data types including integers, floats, boolean, and nulls.
Expected behavior:
Actual behavior is that these values become quoted strings:
Handling of nil/null's is trickier.... but they are not quoted in JSON either.
Related: Issue #81 and Issue #71