Commit f0a1db1c authored by Marek Vavrusa's avatar Marek Vavrusa

daemon: fix serialization of empty nested tables

parent 581cf904
...@@ -289,23 +289,24 @@ static JsonNode *l_pack_elem(lua_State *L, int top) ...@@ -289,23 +289,24 @@ static JsonNode *l_pack_elem(lua_State *L, int top)
JsonNode *node = NULL; JsonNode *node = NULL;
lua_pushnil(L); lua_pushnil(L);
while(lua_next(L, top) != 0) { while(lua_next(L, top) != 0) {
JsonNode *val = l_pack_elem(L, top + 2); const bool is_array = lua_isnumber(L, top + 1);
const bool no_key = lua_isnumber(L, top + 1);
if (!node) { if (!node) {
node = no_key ? json_mkarray() : json_mkobject(); node = is_array ? json_mkarray() : json_mkobject();
if (!node) { if (!node) {
return NULL; return NULL;
} }
} }
/* Insert to array/table */ /* Insert to array/table. */
if (no_key) { JsonNode *val = l_pack_elem(L, top + 2);
if (is_array) {
json_append_element(node, val); json_append_element(node, val);
} else { } else {
json_append_member(node, lua_tostring(L, top + 1), val); json_append_member(node, lua_tostring(L, top + 1), val);
} }
lua_pop(L, 1); lua_pop(L, 1);
} }
return node; /* Return empty object for empty tables. */
return node ? node : json_mkobject();
} }
/** @internal Serialize to string */ /** @internal Serialize to string */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment