luci-lib-json: ignore null keys to allow encoding empty objects
There is currently no way to encode an empty object {}, as empty tables are encoded as empty lists []. With this patch, encode() will ignore table fields with the key json.null (which doesn't make sense anyways). This allows adding a field with key json.null to force encoding it as an object. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
This commit is contained in:
parent
a835fc013b
commit
304eec2eba
1 changed files with 7 additions and 5 deletions
|
@ -149,12 +149,14 @@ function Encoder.parse_iter(self, obj)
|
||||||
local first = true
|
local first = true
|
||||||
|
|
||||||
for key, entry in pairs(obj) do
|
for key, entry in pairs(obj) do
|
||||||
|
if key ~= null then
|
||||||
first = first or self:put(",")
|
first = first or self:put(",")
|
||||||
first = first and false
|
first = first and false
|
||||||
self:parse_string(tostring(key))
|
self:parse_string(tostring(key))
|
||||||
self:put(":")
|
self:put(":")
|
||||||
self:dispatch(entry)
|
self:dispatch(entry)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:put("}")
|
self:put("}")
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue