michalmuskala / jason

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

How to encode maps with integer keys? #105

Closed larskluge closed 4 years ago

larskluge commented 4 years ago

I noticed that maps with integer keys get converted to string keys upon encode. This is not a behavior I'd expect and am quite puzzled about (why is this the case?).

According to tests, this is desired behavior: https://github.com/michalmuskala/jason/blob/70b046aee882ca789bebf3a7d173e6259f3fa8aa/test/encode_test.exs#L52

However, how can I encode a map with integer keys as integer keys?

Example:

Jason.encode! %{42 => :bar}

Desired: {42:"bar"} Actual: {"42":"bar"}

Thank you!

larskluge commented 4 years ago

Just realized JSON allows keys to only be strings. My bad.