robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8f584031bc
master
1---@meta 2-- This file is NOT generated, edit it directly. 3error ( 'Cannot require a meta file' ) 4 5---@nodoc 6vim . json ={} 7 8-- luacheck: no unused args 9 10--- @class vim.json.decode.Opts 11--- @inlinedoc 12--- 13--- Convert JSON "null" in objects/arrays to Lua `nil` instead of |vim.NIL|. 14--- (default: `nil`) 15--- @field luanil? { object?: boolean, array?: boolean } 16--- 17--- Allows JavaScript-style comments within JSON data. Comments are treated as whitespace and may 18--- appear anywhere whitespace is valid in JSON. Supports single-line comments beginning with '//' 19--- and block comments enclosed with '/*' and '*/'. 20--- (default: `false`) 21--- @field skip_comments? boolean 22 23--- @class vim.json.encode.Opts 24--- @inlinedoc 25--- 26--- Escape slash characters "/" in string values. 27--- (default: `false`) 28--- @field escape_slash? boolean 29--- 30--- If non-empty, each value in a JSON object or array starts on a new line and is prefixed with 31--- `indent` per nesting level. Adds a space after colons. Does not add a final newline. 32--- (default: `""`) 33--- @field indent? string 34--- 35--- Sort object keys in alphabetical order. 36--- (default: `false`) 37--- @field sort_keys? boolean 38 39---@brief 40--- 41--- This module provides encoding and decoding of Lua objects to and 42--- from JSON-encoded strings. Supports |vim.NIL| and |vim.empty_dict()|. 43 44--- Decodes (or "unpacks") stringified JSON to a Lua object. 45--- 46--- - Decodes JSON "null" as |vim.NIL| (controllable by {opts}, see below). 47--- - Decodes empty object as |vim.empty_dict()|. 48--- - Decodes empty array as `{}` (empty Lua table). 49--- 50--- Example: 51--- 52--- ```lua 53--- vim.print(vim.json.decode('{"bar":[],"foo":{},"zub":null}')) 54--- -- { bar = {}, foo = vim.empty_dict(), zub = vim.NIL } 55--- ``` 56--- 57---@param str string Stringified JSON data. 58---@param opts? vim.json.decode.Opts 59---@return any 60function vim . json . decode ( str , opts ) end 61 62--- Encodes (or "packs") a Lua object to stringified JSON. 63--- 64--- Example: Implement a basic 'formatexpr' for JSON, so |gq| with a motion formats JSON in 65--- a buffer. (The motion must operate on a valid JSON object.) 66--- 67--- ```lua 68--- function _G.fmt_json() 69--- local indent = vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t' 70--- local lines = vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum + vim.v.count - 1, true) 71--- local o = vim.json.decode(table.concat(lines, '\n')) 72--- local stringified = vim.json.encode(o, { indent = indent, sort_keys = true }) 73--- lines = vim.split(stringified, '\n') 74--- vim.api.nvim_buf_set_lines(0, vim.v.lnum - 1, vim.v.count, true, lines) 75--- end 76--- vim.o.formatexpr = 'v:lua.fmt_json()' 77--- ``` 78--- 79---@param obj any 80---@param opts? vim.json.encode.Opts 81---@return string 82function vim . json . encode ( obj , opts ) end