Skip to content

Replace Jason with Elixir's built-in JSON module#730

Open
Sim-hu wants to merge 1 commit into
Kraigie:masterfrom
Sim-hu:replace-jason-with-json
Open

Replace Jason with Elixir's built-in JSON module#730
Sim-hu wants to merge 1 commit into
Kraigie:masterfrom
Sim-hu:replace-jason-with-json

Conversation

@Sim-hu

@Sim-hu Sim-hu commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the external jason dependency with Elixir 1.18's built-in JSON module, as proposed in #666.

Changes

  • 29 files changed, net reduction of 24 lines
  • All Jason.decode!/Jason.decode calls replaced with JSON.decode!/JSON.decode
  • All Jason.encode_to_iodata! calls replaced with JSON.encode_to_iodata!
  • All @derive Jason.Encoder replaced with @derive JSON.Encoder
  • Custom Jason.Encoder protocol implementations (embed structs) rewritten for JSON.Encoder
  • keys: :atoms option replaced with Util.safe_atom_map/1 (already used elsewhere in the codebase for atom key conversion)
  • Minimum Elixir version bumped to ~> 1.18
  • jason removed from deps in mix.exs

Notes

  • Chose Elixir's JSON module over raw :json + :json_polyfill since the discussion in Replace Jason with :json #666 leaned this way and it provides JSON.Encoder protocol which simplifies the migration
  • The JSON.encode_to_iodata!/1 function is available in Elixir 1.18, keeping the iodata optimization for HTTP request bodies
  • Util.safe_atom_map/1 is functionally equivalent to Jason's keys: :atoms — it recursively converts string keys to atoms with safety checks

Testing

  • mix compile --warnings-as-errors passes
  • mix test — 212 tests, 0 failures

Closes #666

Migrate all JSON encoding/decoding from the external Jason library
to Elixir 1.18's built-in JSON module, removing the jason dependency.

- Replace Jason.decode!/Jason.decode with JSON.decode!/JSON.decode
- Replace Jason.encode_to_iodata! with JSON.encode_to_iodata!
- Replace @derive Jason.Encoder with @derive JSON.Encoder
- Rewrite custom Jason.Encoder implementations to JSON.Encoder
- Use Util.safe_atom_map/1 for atom key conversion (replaces
  Jason's keys: :atoms option)
- Bump minimum Elixir version to ~> 1.18

Closes Kraigie#666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Jason with :json

1 participant