Update json.lua

add a dummy key { _ = false } to force empty table to be encoded to as an object
pull/40/head
luistung 2022-09-22 18:50:22 +08:00 committed by GitHub
parent dbf4b2dd2e
commit c2aad59ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -90,7 +90,9 @@ local function encode_table(val, stack)
if type(k) ~= "string" then
error("invalid table: mixed or invalid key types")
end
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
if k ~= "_" then
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
end
end
stack[val] = nil
return "{" .. table.concat(res, ",") .. "}"