summaryrefslogtreecommitdiffstatshomepage
path: root/src/cjson
AgeCommit message (Collapse)AuthorFiles
2026-02-11feat(stdlib): vim.json.decode() can allow comments #37795skewb1k1
Problem: `vim.json.decode()` could not parse JSONC (JSON with Comments) extension, which is commonly used in configuration files. Solution: Introduce an `skip_comments` option, which is disabled by default. When enabled, allows JavaScript-style comments within JSON data.
2026-01-12docs: misc (#37281)zeertzjq1
Close #37289 Close #37348 Co-authored-by: Marc Jakobi <marc@jakobi.dev> Co-authored-by: Anton Kesy <anton@kesy.de>
2025-09-13feat(json): vim.json.encode() sort_keys #35574skewb1k1
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.
2025-09-10fix(vim.json): fix truncation of decoded numbers outside lua_Integer's range ↵James McCoy1
#35702 PR #34876 expanded the total range of values that cjson considers valid. However, it didn't address the bigger problem of storing a `long long` value in a `lua_Integer` (which is typically a typedef for `ptrdiff_t`). On 32-bit platforms, this ends up storing an 8-byte number into a 4-byte variable, truncating the value. Store the converted value in a temporary `long long` variable so we can detect the scenario and decode into a `lua_Number`.
2025-09-07fix(cjson): fix `strbuf_set_length` incorrectness #35565skewb1k3
`strbuf_set_length` was incorrectly updating length with `+=` instead of assignment. Also syncs minor updates with upstream.
2025-09-07feat(json): pretty-format (indent) with vim.json.encode() #35424skewb1k1
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
2025-07-10fix(vim.json): loss of precision on integers >14 digits #34876jade1
Problem: multiple DAP servers keep assuming they can have internal IDs up to 2**52, which get corrupted by the Neovim JSON encoder. Solution: change (1) constant and add a test so nobody breaks it while updating the library. Fixes: https://github.com/neovim/neovim/issues/24532 Fixes: https://github.com/mfussenegger/nvim-dap/issues/1534 Fixes: https://github.com/facebook/buck2/issues/1032
2025-04-13docs: misc (#33093)dundargoc1
Co-authored-by: Jx <JxJxxJxJ@github.com> Co-authored-by: Richard Dzenis <richard@dzenis.dev> Co-authored-by: Shixian Sheng <shixian_sheng-2@protonmail.com> Co-authored-by: Sourabh Kumar <sourabh7.tech@gmail.com> Co-authored-by: Yegor Yefremov <yegorslists@googlemail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2025-02-26build(cjson): sync with upstream (#32114)Tristan Knight4
Sync with commit https://github.com/openresty/lua-cjson/commit/91ca29db9a4a4fd0eedaebcd5d5f3ba2ace5ae63
2024-12-06feat(stdlib): vim.json.encode(...,{escape_slash:boolean}) #30561Bartłomiej Maryńczak1
Problem: vim.json.encode escapes every slash in string values (for example in file paths), and is not optional. Use-case is for preventing HTML injections (eg. injecting `</script>` closing tag); in the context of Nvim this is rarely useful. Solution: - Add a `escape_slash` flag to `vim.json.encode`. - Defaults to `false`. (This is a "breaking" change, but more like a bug fix.)
2024-05-03fix(vim.json): properly treat luanil options as booleans (#28622)zeertzjq1
Note: Upstream doesn't have this. It's an Nvim addition.
2023-06-21fix(vim.json)!: remove global options, "null", "array_mt" #24070Justin M. Keyes1
Problem: - `vim.json` exposes various global options which: - affect all Nvim Lua plugins (especially the LSP client) - are undocumented and untested - can cause confusing problems such as: https://github.com/codota/tabnine-nvim/commit/cc76ae3abe2f129d44b5a8edee2529e0ee0dcf69 - `vim.json` exposes redundant mechanisms: - `vim.json.null` is redundant with `vim.NIL`. - `array_mt` is redundant because Nvim uses a metatable (`vim.empty_dict()`) for empty dict instead, which `vim.json` is configured to use by default (see `as_empty_dict`). Example: ``` :lua vim.print(vim.json.decode('{"bar":[],"foo":{}}')) --> { bar = {}, foo = vim.empty_dict() } ``` Thus we don't need to also decorate empty arrays with `array_mt`. Solution: Remove the functions from the public vim.json interface. Comment-out the implementation code to minimize drift from upstream. TODO: - Expose the options as arguments to `vim.json.new()`
2023-02-18fix: Add missing void as function argument (#22317)Andreas Schneider1
2022-03-04refactor: fix clang-tidy bugprone-signed-char-misuse warningsDundar Göc1
Prefer to declare variables with correct type instead of explicit casts wherever possible.
2022-02-26feat(lua): add proper support of luv threadserw71
2021-10-05feat(lsp): improve json deserialization performance (#15854)Michael Lingelbach1
* Add optional second table argument to vim.json.decode which takes a table 'luanil' which can include the 'object' and/or 'array' keys. These options use luanil when converting NULL in json objects and arrays respectively. The default behavior matches the original lua-cjson. * Remove recursive_convert_NIL function from rpc.lua, use vim.json.decode with luanil = { object = true } instead. This removes a hotpath in the json deserialization pipeline by dropping keys with json NULL values throughout the deserialized table.
2021-09-26feat(lua): expose lua-cjson as vim.jsonMichael Lingelbach4
* add vim.json.encode and vim.json.decode * use vim.NIL instead of cjson.null * resolve strict-prototypes warnings * The following benchmark shows an approximately 2.5x (750 ms vs 300 ms) improvement in deserialization performance over vim.fn.json_decode on a medium package.json ```lua local uv = vim.loop local function readfile(path) return end local json_url = "https://raw.githubusercontent.com/rust-analyzer/rust-analyzer/b24c8d5c89ee93d1172b4127564f5da3b0c88dad/editors/code/package.json" io.popen(string.format('curl -v -f -L -O %q &> /dev/null', json_url)) local json_string = io.open('package.json'):read '*a' uv.update_time() local start = uv.hrtime() for i = 1,1000 do vim.fn.json_decode(json_string) end uv.update_time() print(string.format("Deserialization time vim.fn.json_decode: %s ms", (uv.hrtime() - start) * (1e-6))) uv.update_time() local start = uv.hrtime() for i = 1,1000 do vim.json.decode(json_string) end uv.update_time() print(string.format("Deserialization time vim.json.decode: %s ms", (uv.hrtime() - start) * (1e-6))) ``` Co-Authored-By: Björn Linse <bjorn.linse@gmail.com>
2021-09-26feat(lua): add lua-cjson as vendored dependencyMichael Lingelbach5
Derived from the openresty lua-cjson fork at commit https://github.com/openresty/lua-cjson/commit/3d93d297092172eac3d52a1b3b6c1d479da5341a