Skip to content

Conversation

@skewb1k
Copy link

@skewb1k skewb1k commented Aug 30, 2025

Adds cjson.encode_sort_keys(enabled) option.

If enabled, keys in encoded objects will be sorted in alphabetical order.

Fixes #66

@skewb1k skewb1k force-pushed the feat/sort-keys branch 2 times, most recently from 91af5a5 to 51bace7 Compare August 31, 2025 18:54
skewb1k added a commit to skewb1k/neovim that referenced this pull request Aug 31, 2025
Problem: There is no way to ensure a stable key order when encoding a JSON string,
which can be useful for comparisons and producing cleaner diffs.

Solution: Introduce a `sort_keys` option for `vim.json.encode()`,which
is disabled by default. When enabled, object keys are sorted in
alphabetical order.

Adapts PR to upstream: openresty/lua-cjson#115.
@skewb1k skewb1k marked this pull request as ready for review August 31, 2025 19:41
skewb1k added a commit to skewb1k/neovim that referenced this pull request Aug 31, 2025
Problem: There is no way to ensure a stable key order when encoding a JSON string,
which can be useful for comparisons and producing cleaner diffs.

Solution: Introduce a `sort_keys` option for `vim.json.encode()`,which
is disabled by default. When enabled, object keys are sorted in
alphabetical order.

Adapts PR to upstream: openresty/lua-cjson#115.
skewb1k added a commit to skewb1k/neovim that referenced this pull request Sep 9, 2025
Problem: There is no way to ensure a stable key order when encoding a JSON string,
which can be useful for comparisons and producing cleaner diffs.

Solution: Introduce a `sort_keys` option for `vim.json.encode()`,which
is disabled by default. When enabled, object keys are sorted in
alphabetical order.

Adapts PR to upstream: openresty/lua-cjson#115.
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.

cjson.encode() modified order

1 participant