aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_meta/json.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-07-17 17:40:14 +0100
committerGitHub <noreply@github.com>2023-07-17 17:40:14 +0100
commit80cf0f3d29fa337d43ec417759cb061bd2798ea8 (patch)
tree16de8180f2fb9feefd0df94e0c8598475ec28324 /runtime/lua/vim/_meta/json.lua
parent1b9ccd38a12f8fdbdff51ef0b3ff363540f745ec (diff)
parent6e9b204afbe5f16c44a2697aed07aafff36bf856 (diff)
downloadrneovim-80cf0f3d29fa337d43ec417759cb061bd2798ea8.tar.gz
rneovim-80cf0f3d29fa337d43ec417759cb061bd2798ea8.tar.bz2
rneovim-80cf0f3d29fa337d43ec417759cb061bd2798ea8.zip
Merge pull request #24363 from lewis6991/docs/luatypes
docs(lua): move some function docs to lua files
Diffstat (limited to 'runtime/lua/vim/_meta/json.lua')
-rw-r--r--runtime/lua/vim/_meta/json.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/lua/vim/_meta/json.lua b/runtime/lua/vim/_meta/json.lua
new file mode 100644
index 0000000000..76a6c7b733
--- /dev/null
+++ b/runtime/lua/vim/_meta/json.lua
@@ -0,0 +1,37 @@
+--- @meta
+
+-- luacheck: no unused args
+
+--- @defgroup vim.json
+---
+--- This module provides encoding and decoding of Lua objects to and
+--- from JSON-encoded strings. Supports |vim.NIL| and |vim.empty_dict()|.
+
+--- 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:
+--- <pre>lua
+--- :lua vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}'))
+--- --> { bar = {}, foo = vim.empty_dict(), zub = vim.NIL }
+--- </pre>
+--- Parameters: ~
+--- • {str} Stringified JSON data.
+--- • {opts} Options map keys:
+--- • luanil: { object: bool, array: bool }
+--- • `luanil.object=true` converts `null` in JSON objects to
+--- Lua `nil` instead of `vim.NIL`.
+--- • `luanil.array=true` converts `null` in JSON arrays to Lua
+--- `nil` instead of `vim.NIL`.
+--- @param str string
+--- @param opts? table<string, any>
+--- @return any
+function vim.json.decode(str, opts) end
+
+--- Encodes (or "packs") Lua object {obj} as JSON in a Lua string.
+--- @param obj any
+--- @return string
+function vim.json.encode(obj) end