summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/lua/json_spec.lua
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.
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-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-01-01docs: misc #31479Justin M. Keyes1
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.
2024-04-23test: improve test conventionsdundargoc1
Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
2024-04-10refactor(test): inject after_each differentlyLewis Russell1
2024-04-08test: improve test conventionsdundargoc1
Work on https://github.com/neovim/neovim/issues/27004.
2024-01-03refactor: format test/*Justin M. Keyes1
2023-12-06fix(json): allow objects with empty keys #25564Emanuel1
Problem: Empty string is a valid JSON key, but json_decode() treats an object with empty key as ":help msgpack-special-dict". #20757 :echo json_decode('{"": "1"}') {'_TYPE': [], '_VAL': [['', '1']]} Note: vim returns `{'': '1'}`. Solution: Allow empty string as an object key. Note that we still (currently) disallow empty keys in object_to_vim() (since 7c01d5ff9286d262097484c680e3a4eab49e2911): https://github.com/neovim/neovim/blob/f64e4b43e1191ff30d902730f752875aa55682ce/src/nvim/api/private/converter.c#L333-L334 Fix #20757 Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
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()`
2021-09-26test: add tests for vim.jsonMichael Lingelbach1