michalmuskala / jason

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

Proposal: Consistent number decoding #164

Open ulissesalmeida opened 1 year ago

ulissesalmeida commented 1 year ago

Hi,

Today we have this option: floats: :decimal | :native.

It works pretty when you want Decimal.t() from instead of float, however if the API you're consuming sometimes outputs 3 (integers), you get a native integer number after decoding. So the rest of the code has to handle Decimal.t() or integer() types, or add a code to normalise it before exposing it to the rest of the application.

I wonder if it would be better or possible to have a option like numbers: :binary | :decimal | :native instead. So you could have all numbers normalised in a single shape right (String.t() | Decimal.t() | number()) after decoding.

What do you think?