Replace Jason with Elixir's built-in JSON module#730
Open
Sim-hu wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the external
jasondependency with Elixir 1.18's built-inJSONmodule, as proposed in #666.Changes
Jason.decode!/Jason.decodecalls replaced withJSON.decode!/JSON.decodeJason.encode_to_iodata!calls replaced withJSON.encode_to_iodata!@derive Jason.Encoderreplaced with@derive JSON.EncoderJason.Encoderprotocol implementations (embed structs) rewritten forJSON.Encoderkeys: :atomsoption replaced withUtil.safe_atom_map/1(already used elsewhere in the codebase for atom key conversion)~> 1.18jasonremoved from deps in mix.exsNotes
JSONmodule over raw:json+:json_polyfillsince the discussion in Replace Jason with :json #666 leaned this way and it providesJSON.Encoderprotocol which simplifies the migrationJSON.encode_to_iodata!/1function is available in Elixir 1.18, keeping the iodata optimization for HTTP request bodiesUtil.safe_atom_map/1is functionally equivalent to Jason'skeys: :atoms— it recursively converts string keys to atoms with safety checksTesting
mix compile --warnings-as-errorspassesmix test— 212 tests, 0 failuresCloses #666