jason
jason copied to clipboard
Map key validity/order in Elixir 1.14
I have been using Jason to encode Elixir maps into Jason in docs generated at compile time. That had been working fine until upgrading to Elixir 1.14 when suddenly docs kept changing after compilation do to differently ordered Jason keys.
I quickly realized that, in retrospect, it was a mistake to rely on maps for this since their order is explicitly not guaranteed. After some digging I saw that Jason.Helpers
provides json_map/1
to transform an ordered keyword list into a json object, so I assume that would be the right tool for this problem.
However, when I started converting the docs I ran into a compilation error for a API response that includes a /
(see livemd below). Is there something about the JSON spec I'm not aware of that would explain this behavior?
Jason json_map
Mix.install([
{:jason, "~> 1.4"}
])
Section
require Jason.Helpers
Jason.Helpers.json_map("my/key": "test")