feat(stdlib): vim.json.decode() can allow comments #37795

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.
This commit is contained in:
skewb1k
2026-02-11 14:54:57 +03:00
committed by GitHub
parent 3567b7d751
commit 6b4ec2264e
5 changed files with 106 additions and 11 deletions

View File

@@ -11,15 +11,20 @@ vim.json = {}
--- Convert `null` in JSON objects and/or arrays to Lua `nil` instead of |vim.NIL|.
--- (default: `nil`)
--- @field luanil? { object?: boolean, array?: boolean }
---
--- Allows JavaScript-style comments within JSON data. Comments are treated as whitespace and may
--- appear anywhere whitespace is valid in JSON. Supports single-line comments beginning with '//'
--- and block comments enclosed with '/*' and '*/'.
--- (default: `false`)
--- @field skip_comments? boolean
--- @class vim.json.encode.Opts
--- @inlinedoc
---
--- Escape slash characters "/" in string values.
--- Escape slash characters "/" in string values.
--- (default: `false`)
--- @field escape_slash? boolean
---
---
--- If non-empty, the returned JSON is formatted with newlines and whitespace, where `indent`
--- defines the whitespace at each nesting level.
--- (default: `""`)