Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support native JSON module #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

crbelaus
Copy link
Contributor

@crbelaus crbelaus commented Mar 2, 2025

Since Elixir 1.18 there is a native JSON module, so new projects don't need Jason and many don't have it. This pull request updates the error tracker so:

  • Jason is an optional dependency as the error tracker can work without it
  • We try to use the user-defined JSON library (just like we did before) but if none is defined we default to the native JSON module for Elixir 1.18 and newer. On older versions we still default to Jason just like we did before.
  • We use the encode_to_iodata! function which is the most performant and provided by both libraries.
  • The JSON module can't pretty print like Jason does. Instead we are now pretty printing in the client using JSON.stringify which is widely available across all browsers.

There should not be any user-facing changes. Users will still see the JSON context formatted just like they did before but now the ErrorTracker works well on Elixir 1.18 and newer projects that don't include Jason. We also don't force it for such projects as a native alternative exists.

Closes #131

@crbelaus crbelaus requested a review from odarriba March 2, 2025 10:06
@crbelaus crbelaus self-assigned this Mar 2, 2025
@crbelaus crbelaus changed the base branch from main to mute-errors March 2, 2025 10:07
Base automatically changed from mute-errors to main March 3, 2025 14:28
crbelaus added 3 commits March 3, 2025 15:30
Elixir 1.18+ comes with the JSON module out of the box so there is no
need for Jason anymore. This commit marks Jason as an optional
dependency and upates the code to use JSON if available and Jason for
older Elixir versions.
@crbelaus crbelaus force-pushed the support-native-json-module branch from 34f541f to ce91c57 Compare March 3, 2025 14:30
@crbelaus
Copy link
Contributor Author

crbelaus commented Mar 3, 2025

I've just run mix assets.build, not sure why there are so many changes in the app.js file 🤔

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.

Support JSON from Elixir 1.18
1 participant