Skip to content

fix (config): deterministic JSON key ordering for config.json#944

Open
kisst wants to merge 1 commit into
mickael-kerjean:masterfrom
kisst:fix/deterministic-config-json-key-order
Open

fix (config): deterministic JSON key ordering for config.json#944
kisst wants to merge 1 commit into
mickael-kerjean:masterfrom
kisst:fix/deterministic-config-json-key-order

Conversation

@kisst
Copy link
Copy Markdown

@kisst kisst commented Mar 5, 2026

Summary

  • The connections field ([]map[string]any) in config was serialized using json.Marshal, which produces non-deterministic key ordering due to Go's random map iteration order
  • This caused spurious diffs when config.json is kept under version control — keys would randomly reorder on every save even when no actual values changed
  • Replaced json.Marshal with a custom marshaler that sorts map keys alphabetically before serialization, ensuring stable and deterministic output

Test plan

  • Verify config saves produce identical output when no values have changed
  • Verify config saves correctly reflect actual value changes
  • Verify nested map values in connections are also sorted deterministically

The connections field ([]map[string]any) was serialized using
json.Marshal which produces non-deterministic key ordering due to
Go's random map iteration. This caused spurious diffs when the
config file is kept under version control.

Replace json.Marshal with a custom marshaler that sorts map keys
before serialization, ensuring stable output across saves.
@kisst
Copy link
Copy Markdown
Author

kisst commented Mar 18, 2026

@mickael-kerjean can you check this, I am spamming my filestash config git repo with a bunch of meaningless changes.

@mickael-kerjean
Copy link
Copy Markdown
Owner

I am head deep in some other things, I will give it a look when I have some time

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