diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-06-04 21:03:24 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-06-04 21:13:41 +0200 |
commit | 304eec2ebaf983fd067e5ae719f8ec023aad8b30 (patch) | |
tree | 32a1aa489cc7414d135070691141bd8e3faf097d /libs/luci-lib-json/luasrc/json.lua | |
parent | a835fc013b1420666e2a437b963ef7c5f07aea69 (diff) |
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>
Diffstat (limited to 'libs/luci-lib-json/luasrc/json.lua')
-rw-r--r-- | libs/luci-lib-json/luasrc/json.lua | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libs/luci-lib-json/luasrc/json.lua b/libs/luci-lib-json/luasrc/json.lua index 416b25faa..f7b57f916 100644 --- a/libs/luci-lib-json/luasrc/json.lua +++ b/libs/luci-lib-json/luasrc/json.lua @@ -149,11 +149,13 @@ function Encoder.parse_iter(self, obj) local first = true for key, entry in pairs(obj) do - first = first or self:put(",") - first = first and false - self:parse_string(tostring(key)) - self:put(":") - self:dispatch(entry) + if key ~= null then + first = first or self:put(",") + first = first and false + self:parse_string(tostring(key)) + self:put(":") + self:dispatch(entry) + end end self:put("}") |