# HG changeset patch # User jbe # Date 1407607632 -7200 # Node ID 1f925cb34299e2f0c8bf780c0589a608539c8461 # Parent f7c1869b5b326df6c058254035a4f1daf1e517b3 Fixed comma setting in json.export(...) diff -r f7c1869b5b32 -r 1f925cb34299 libraries/json/json.c --- a/libraries/json/json.c Sat Aug 09 19:39:16 2014 +0200 +++ b/libraries/json/json.c Sat Aug 09 20:07:12 2014 +0200 @@ -1237,8 +1237,9 @@ return luaL_error(L, "JSON export not possible for values of type \"%s\"", lua_typename(L, lua_type(L, json_export_value_idx))); } if (container) { - // add colon where necessary: + // add colon or comma where necessary: if (containerkey) luaL_addchar(&buf, ':'); + json_export_container: switch (container->type) { case JSON_TABLETYPE_OBJECT: if (container->pos < container->count) { @@ -1273,6 +1274,7 @@ container = lua_touserdata(L, json_export_ccontainer_idx); lua_rawgeti(L, json_export_stackswap_idx, stackswapidx--); lua_replace(L, json_export_luacontainer_idx); + goto json_export_container; } else { // for pretty results, add final newline character if outermost container is processed: if (pretty) luaL_addchar(&buf, '\n'); @@ -1280,24 +1282,25 @@ return 1; } } - /* - if (containerkey || container->type == JSON_TABLETYPE_ARRAY) { - // add comma where necessary: - if (container->pos > 1) luaL_addchar(&buf, ','); - // handle indentation for pretty results: - if (pretty) { - if (containerkey) { - luaL_addchar(&buf, ' '); - } else { - luaL_addchar(&buf, '\n'); - for (i=0; itype == JSON_TABLETYPE_OBJECT ? ( + container->pos && containerkey + ) : ( + container->pos > 1 + ) + ) luaL_addchar(&buf, ','); + // handle indentation for pretty results: + if (pretty) { + if (containerkey) { + luaL_addchar(&buf, ' '); + } else { + luaL_addchar(&buf, '\n'); + for (i=0; i