Skip to content

Conversation

@callahat
Copy link
Contributor

Adds support for passing a sorter to encode
Specs ran against elixir 1.14.0, erlang 23.3.4.20
and elixir elixir 1.18.3-otp-27, erlang 27.3.3

Sorter support for List.keysort was added in elixir 1.14 - https://hexdocs.pm/elixir/1.14.0/List.html#keysort/3 hence the major version bump (in addition to an additional parameter being added to StableJason.encode functions)

callahat added 2 commits June 29, 2025 07:40
Update ci.yml to remove elixir 1.13 from the matrix, add elixir 1.17 and elixir 1.18
@egze
Copy link
Owner

egze commented Jun 29, 2025

@callahat Thank you for the PR. I'll merge and release a new version in couple of hours.

Just for my curiosity:

  • How are you using StableJason?
  • What is the use case for a custom sorter?

@callahat
Copy link
Contributor Author

@egze You're welcome.

I am using StableJason to prettify JSON being written to a file and checked in to a repo. The JSON is export data that's used to define a game (assets, scripts, maps, etc) written for a custom engine. Being able to have the object keys in a set order should cut down on some of the noise of things shifting about (without actually changing) in the pretty file, which should make it easier to diff between versions of a game to see what is different.

For the custom sorter, I wanted to be able to sort keys based on length then normal order (similar to how numbers are sorted with fewer digits being "higher"). Some of the keys in the JSON export mentioned above are really base 84 numbers - but to represent them the digits are strings - so hopefully this will also cut down a bit on keys shifting around.

@egze egze merged commit 27ff60e into egze:main Jun 29, 2025
5 checks passed
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