Comments (8)
:h lua-table
Like indices, the value of a table field can be of any type (except `nil`). In
particular, because functions are first-class values, table fields may contain
functions. Thus tables may also carry methods (see |lua-function-define|).
from neovim.
Then I suppose the documentation needs to be updated since it states:
:h vim.json.decode
vim.json.decode({str}, {opts}) *vim.json.decode()*
Decodes (or "unpacks") the JSON-encoded {str} to a Lua object.
• Decodes JSON "null" as |vim.NIL| (controllable by {opts}, see below).
• Decodes empty object as |vim.empty_dict()|.
• Decodes empty array as `{}` (empty Lua table).
Example: >lua
vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}'))
-- { bar = {}, foo = vim.empty_dict(), zub = vim.NIL }
<
Parameters: ~
• {str} (`string`) Stringified JSON data.
• {opts} (`table<string,any>?`) Options table with keys:
• luanil: (table) Table with keys:
• object: (boolean) When true, converts `null` in JSON
objects to Lua `nil` instead of |vim.NIL|.
• array: (boolean) When true, converts `null` in JSON arrays
to Lua `nil` instead of |vim.NIL|.
from neovim.
Then I suppose the documentation needs to be updated since it states:
Which part of the doc is wrong?
You can try your expected result directly in Lua, without involving vim.json.decode():
lua vim.print({ zub = nil, bar = {}, foo = vim.empty_dict() })
that prints:
{
bar = {},
foo = vim.empty_dict()
}
Setting a table key to nil
, removes the key.
from neovim.
Yeah, you are right, the documentation is not wrong. It was my assumption of how it would work that was wrong, since I expected that lua-tables could hold nil values. So when I read this:
object: (boolean) When true, converts `null` in JSON
objects to Lua `nil` instead of |vim.NIL|.
I did not expect them to disappear.
But is it not strange that if I run this configuration:
vim.json.decode('{"bar":[],"foo":{},"zub":null}', { luanil = { object = false, array = false }})
I still get:
{
bar = {},
foo = vim.empty_dict()
}
Anyway, thanks for the help, much appreciated.
from neovim.
But is it not strange that if I run this configuration:
vim.json.decode('{"bar":[],"foo":{},"zub":null}', { luanil = { object = false, array = false }})I still get:
{ bar = {}, foo = vim.empty_dict() }
that does seem like a bug
from neovim.
It seems that these aren't actually boolean keys. Setting them to any value except nil
behaves like true
.
from neovim.
Upstream doesn't have luanil
. It's an Nvim addition.
from neovim.
Yes, that was my point. But never mind.
from neovim.
Related Issues (20)
- resolv doesn't recognise `search .` and `trust-ad` HOT 1
- No colours when using command filter HOT 3
- `:set` doesn't clear old messages with ext_cmdline HOT 1
- Update tests to use default color scheme
- Lua/stdlib: behavior of global vs local "enable" (and other config) HOT 1
- Show selected popupmenu item using virtual text
- OSC52 very slow in Windows Terminal (workaround provided) HOT 3
- `nvim_buf_set_text` resets changelist to 0 HOT 2
- inlay_hint `enable(<no args>)` does not activate inlay hints on open buffers HOT 13
- Local and global inlay hints not interacting correctly together HOT 4
- editorconfig: support spelling_language property
- Folding Breaks When First Line of Method Is A Multiline Comment HOT 3
- "crr" default mapping does not emit ModeChanged after "c" HOT 14
- A syntax for Typescript is broken. HOT 7
- Winbar UI inconsistent with multiple tabs HOT 1
- incorrect detection of ruby neovim in checkhealth HOT 1
- Segfault when editing html part in markdown HOT 3
- nnoremap c s dont work anymore HOT 2
- built-in commenting does not use whitespaces depending on 'commentstring' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neovim.