option to force to encode empty table to "[]"
Since lua-cjson use table index type to decide the result json type that a lua table is encoded to, there is no way to encode empty lua table to a list in json.
This patch solves this problem by assigning a special meta-table to an empty table to force it to be encoded to "[]" instead of "{}":
local t = {}
setmetatable(t,cjson.as_array)
json.encode(t) -- > "[]"
:+1:
Why is it still open? I need this feature and don't want to fork it.. Is there a workaround for this?
any progress for this PR?
@moooofly It seems the author has no intent to merge it. :(
@drmingdrmer anyway, this PR helps me a lot, I've patched this code into https://github.com/antirez/redis/blob/unstable/deps/lua/src/lua_cjson.c , and works well.
Thanks a lot.