aboutsummaryrefslogtreecommitdiff
path: root/json.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-01 23:24:22 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-01-01 23:24:22 +0100
commite41ab2b985c03477025cb518dc8f7903f597e5d9 (patch)
tree0d7d6afd9206e65504eadfadd9b2cdd532e71d0d /json.lua
parent8fb904d27f2f7a7f6dbe541605a367c4a88dec0f (diff)
downloadvis-lspc-e41ab2b985c03477025cb518dc8f7903f597e5d9.tar.gz
vis-lspc-e41ab2b985c03477025cb518dc8f7903f597e5d9.zip
fallback json: support explicit null encoding
Diffstat (limited to 'json.lua')
-rw-r--r--json.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/json.lua b/json.lua
index ede894a..631e7f5 100644
--- a/json.lua
+++ b/json.lua
@@ -17,8 +17,8 @@ object, encoded like so: `{"key1": 2, "key2": false}`.
Because the Lua nil value cannot be a key, and as a table value is considerd
equivalent to a missing key, there is no way to express the json "null" value in
-a Lua table. The only way this will output "null" is if your entire input obj is
-nil itself.
+a Lua table. The json.null table can be used to encode the json "null" value.
+{key=json.null} will be encoded to `{"key":null}`.
An empty Lua table, {}, could be considered either a json object or array -
it's an ambiguous edge case. We choose to treat this as an object as it is the
@@ -51,6 +51,9 @@ local json = {}
-- Internal functions.
local function kind_of(obj)
+ if obj == json.null then
+ return 'nil'
+ end
if type(obj) ~= 'table' then return type(obj) end
local i = 1
for _ in pairs(obj) do