neovim/runtime/lua/vim/_meta/json.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.4 KiB
Lua
Raw Normal View History

2023-09-14 06:23:01 -07:00
---@meta
2023-09-22 13:00:31 -07:00
---@nodoc
vim.json = {}
2023-07-17 08:32:56 -07:00
-- luacheck: no unused args
2023-09-14 06:23:01 -07:00
---@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:
2023-09-14 06:23:01 -07:00
---
--- ```lua
--- vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}'))
--- -- { bar = {}, foo = vim.empty_dict(), zub = vim.NIL }
--- ```
---
---@param str string Stringified JSON data.
---@param 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|.
---@return any
function vim.json.decode(str, opts) end
--- Encodes (or "packs") Lua object {obj} as JSON in a Lua string.
2023-09-14 06:23:01 -07:00
---@param obj any
---@return string
function vim.json.encode(obj) end