feat(json): pretty-format (indent) with vim.json.encode() #35424

Problem:
There is no straightforward way to pretty-print objects as JSON.
The existing `vim.inspect` outputs LON.

Solution:
Introduce an `indent` option for `vim.json.encode()` which enables
human-readable output with configurable indentation.

Adapts PR to upstream: openresty/lua-cjson#114
This commit is contained in:
skewb1k
2025-09-08 00:38:27 +03:00
committed by GitHub
parent 2b156be19c
commit 448f15ca39
5 changed files with 125 additions and 17 deletions

View File

@@ -38,5 +38,7 @@ function vim.json.decode(str, opts) end
---@param opts? table<string,any> Options table with keys:
--- - escape_slash: (boolean) (default false) Escape slash
--- 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.
---@return string
function vim.json.encode(obj, opts) end