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

fix: use external_size instead of encoding json #2267

Merged
merged 1 commit into from
Dec 4, 2024
Merged

Conversation

chasers
Copy link
Contributor

@chasers chasers commented Dec 4, 2024

Calculating JSON Size

Mix.install([
  {:jason, "~> 1.4"}
])

JSON

json = """
PRIVATE
"""

decoded = Jason.decode!(json)

hiding_output = nil
nil

IO.iodata_length

decoded
|> Jason.encode!()
|> inspect(
  binaries: :as_strings,
  charlists: :as_lists,
  limit: :infinity,
  printable_limit: :infinity
)
|> IO.iodata_length()
3362

:erlang.byte_size

decoded |> :erlang.term_to_binary() |> :erlang.byte_size()
3408
json |> :erlang.byte_size()
4125

:erlang.external_size

decoded |> :erlang.external_size()
3408

@chasers chasers requested a review from Ziinc December 4, 2024 14:05
@Ziinc Ziinc merged commit 3a1494d into main Dec 4, 2024
6 checks passed
@Ziinc Ziinc deleted the fix/external-size branch December 4, 2024 14:25
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.

2 participants