mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 01:08:20 +00:00
feat(json): vim.json.encode() sort_keys #35574
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.
This commit is contained in:
@@ -3391,6 +3391,8 @@ vim.json.encode({obj}, {opts}) *vim.json.encode()*
|
||||
• indent: (string) (default "") String used for indentation at
|
||||
each nesting level. If non-empty enables newlines and a
|
||||
space after colons.
|
||||
• sort_keys: (boolean) (default false) Sort object keys in
|
||||
alphabetical order.
|
||||
|
||||
Return: ~
|
||||
(`string`)
|
||||
|
@@ -266,6 +266,7 @@ LUA
|
||||
• |vim.list.bisect()| for binary search.
|
||||
• Experimental `vim.pos` and `vim.range` for Position/Range abstraction.
|
||||
• |vim.json.encode()| has an `indent` option for pretty-formatting.
|
||||
• |vim.json.encode()| has an `sort_keys` option.
|
||||
|
||||
OPTIONS
|
||||
|
||||
|
@@ -56,5 +56,7 @@ function vim.json.decode(str, opts) end
|
||||
--- characters "/" in string values.
|
||||
--- - indent: (string) (default "") String used for indentation at each nesting level.
|
||||
--- If non-empty enables newlines and a space after colons.
|
||||
--- - sort_keys: (boolean) (default false) Sort object
|
||||
--- keys in alphabetical order.
|
||||
---@return string
|
||||
function vim.json.encode(obj, opts) end
|
||||
|
Reference in New Issue
Block a user