mpx / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua
https://kyne.au/~mark/software/lua-cjson.php
MIT License
933 stars 478 forks source link

Adding support for an extra json_encode argument for empty table encoding resolution #48

Closed szakharchenko closed 6 years ago

szakharchenko commented 7 years ago

The extra argument should be a table which, when looked up with an empty table key, would yield a truthy value if that empty table should be encoded as a JSON empty array ([]) instead of an empty object ({}).

Needless to say, the lookup table's metatable is honored so you can in fact do pretty much any checks in its __index metamethod.

This is more flexible than #15 and doesn't require modifying the encoded data like #25.

szakharchenko commented 6 years ago

Actually, I've found that an even more generic solution is even more useful in presence of table.pack(), etc. Disregard this.