michalmuskala/jason

Map key validity/order in Elixir 1.14

オープン

#170 opened on 2023/07/24

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)Elixir (178 件のフォーク)batch import
enhancementhelp wanted

Repository metrics

Stars
 (1,679 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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")

コントリビューターガイド