diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | README.md | 56 | ||||
| -rw-r--r-- | lua-cjson-2.1.0.16-1.rockspec (renamed from lua-cjson-2.1.0.14-1.rockspec) | 4 | ||||
| -rw-r--r-- | lua_cjson.c | 66 | ||||
| -rw-r--r-- | strbuf.c | 8 | ||||
| -rwxr-xr-x | tests/test.lua | 38 |
6 files changed, 166 insertions, 10 deletions
| @@ -23,8 +23,6 @@ LUA_CMODULE_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION) | |||
| 23 | LUA_MODULE_DIR ?= $(PREFIX)/share/lua/$(LUA_VERSION) | 23 | LUA_MODULE_DIR ?= $(PREFIX)/share/lua/$(LUA_VERSION) |
| 24 | LUA_BIN_DIR ?= $(PREFIX)/bin | 24 | LUA_BIN_DIR ?= $(PREFIX)/bin |
| 25 | 25 | ||
| 26 | AR= $(CC) -o | ||
| 27 | |||
| 28 | ##### Platform overrides ##### | 26 | ##### Platform overrides ##### |
| 29 | ## | 27 | ## |
| 30 | ## Tweak one of the platform sections below to suit your situation. | 28 | ## Tweak one of the platform sections below to suit your situation. |
| @@ -99,7 +97,7 @@ all: $(TARGET) | |||
| 99 | doc: manual.html performance.html | 97 | doc: manual.html performance.html |
| 100 | 98 | ||
| 101 | $(TARGET): $(OBJS) | 99 | $(TARGET): $(OBJS) |
| 102 | $(AR) $@ $(LDFLAGS) $(CJSON_LDFLAGS) $(OBJS) | 100 | $(CC) -o $@ $(LDFLAGS) $(CJSON_LDFLAGS) $(OBJS) |
| 103 | 101 | ||
| 104 | install: $(TARGET) | 102 | install: $(TARGET) |
| 105 | mkdir -p $(DESTDIR)$(LUA_CMODULE_DIR) | 103 | mkdir -p $(DESTDIR)$(LUA_CMODULE_DIR) |
| @@ -15,6 +15,8 @@ Table of Contents | |||
| 15 | * [empty_array_mt](#empty_array_mt) | 15 | * [empty_array_mt](#empty_array_mt) |
| 16 | * [encode_number_precision](#encode_number_precision) | 16 | * [encode_number_precision](#encode_number_precision) |
| 17 | * [encode_escape_forward_slash](#encode_escape_forward_slash) | 17 | * [encode_escape_forward_slash](#encode_escape_forward_slash) |
| 18 | * [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types) | ||
| 19 | * [encode_indent](#encode_indent) | ||
| 18 | * [decode_array_with_array_mt](#decode_array_with_array_mt) | 20 | * [decode_array_with_array_mt](#decode_array_with_array_mt) |
| 19 | 21 | ||
| 20 | Description | 22 | Description |
| @@ -171,6 +173,60 @@ If disabled, forward slash '/' will be encoded as '/' (no escape is applied). | |||
| 171 | 173 | ||
| 172 | [Back to TOC](#table-of-contents) | 174 | [Back to TOC](#table-of-contents) |
| 173 | 175 | ||
| 176 | encode_skip_unsupported_value_types | ||
| 177 | --------------------------- | ||
| 178 | **syntax:** `cjson.encode_skip_unsupported_value_types(enabled)` | ||
| 179 | |||
| 180 | **default:** false | ||
| 181 | |||
| 182 | If enabled, cjson will not throw exception when there are unsupported types | ||
| 183 | in the Lua table. | ||
| 184 | |||
| 185 | For example: | ||
| 186 | |||
| 187 | ```lua | ||
| 188 | local ffi = require "ffi" | ||
| 189 | local cjson = require "cjson" | ||
| 190 | cjson.encode_skip_unsupported_value_types(true) | ||
| 191 | local t = {key = "val"} | ||
| 192 | |||
| 193 | t.cdata = ffi.new("char[?]", 100) | ||
| 194 | print(cjson.encode(t)) | ||
| 195 | ``` | ||
| 196 | |||
| 197 | This will generate: | ||
| 198 | |||
| 199 | ```json | ||
| 200 | {"key":"val"} | ||
| 201 | ``` | ||
| 202 | |||
| 203 | [Back to TOC](#table-of-contents) | ||
| 204 | |||
| 205 | encode_indent | ||
| 206 | ---------------------------- | ||
| 207 | **syntax:** `cjson.encode_indent(indent)` | ||
| 208 | |||
| 209 | If non-empty string provided, JSON values encoded by `cjson.encode()` will be | ||
| 210 | formatted in a human-readable way, using `indent` for indentation | ||
| 211 | at each nesting level. Also enables newlines and a space after colons. | ||
| 212 | |||
| 213 | Example: | ||
| 214 | |||
| 215 | ```lua | ||
| 216 | local cjson = require "cjson" | ||
| 217 | |||
| 218 | cjson.encode_indent(" ") | ||
| 219 | print(cjson.encode({ a = 1, b = { c = 2 } })) | ||
| 220 | -- { | ||
| 221 | -- "a": 1, | ||
| 222 | -- "b": { | ||
| 223 | -- "c": 2 | ||
| 224 | -- } | ||
| 225 | -- } | ||
| 226 | ``` | ||
| 227 | |||
| 228 | [Back to TOC](#table-of-contents) | ||
| 229 | |||
| 174 | decode_array_with_array_mt | 230 | decode_array_with_array_mt |
| 175 | -------------------------- | 231 | -------------------------- |
| 176 | **syntax:** `cjson.decode_array_with_array_mt(enabled)` | 232 | **syntax:** `cjson.decode_array_with_array_mt(enabled)` |
diff --git a/lua-cjson-2.1.0.14-1.rockspec b/lua-cjson-2.1.0.16-1.rockspec index 4376a08..037993a 100644 --- a/lua-cjson-2.1.0.14-1.rockspec +++ b/lua-cjson-2.1.0.16-1.rockspec | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | package = "lua-cjson" | 1 | package = "lua-cjson" |
| 2 | version = "2.1.0.14-1" | 2 | version = "2.1.0.16-1" |
| 3 | 3 | ||
| 4 | source = { | 4 | source = { |
| 5 | url = "git+https://github.com/openresty/lua-cjson", | 5 | url = "git+https://github.com/openresty/lua-cjson", |
| 6 | tag = "2.1.0.14", | 6 | tag = "2.1.0.16", |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | description = { | 9 | description = { |
diff --git a/lua_cjson.c b/lua_cjson.c index bbd8eff..789817d 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
| @@ -91,6 +91,7 @@ | |||
| 91 | #define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0 | 91 | #define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0 |
| 92 | #define DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH 1 | 92 | #define DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH 1 |
| 93 | #define DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES 0 | 93 | #define DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES 0 |
| 94 | #define DEFAULT_ENCODE_INDENT NULL | ||
| 94 | 95 | ||
| 95 | #ifdef DISABLE_INVALID_NUMBERS | 96 | #ifdef DISABLE_INVALID_NUMBERS |
| 96 | #undef DEFAULT_DECODE_INVALID_NUMBERS | 97 | #undef DEFAULT_DECODE_INVALID_NUMBERS |
| @@ -172,6 +173,7 @@ typedef struct { | |||
| 172 | int encode_keep_buffer; | 173 | int encode_keep_buffer; |
| 173 | int encode_empty_table_as_object; | 174 | int encode_empty_table_as_object; |
| 174 | int encode_escape_forward_slash; | 175 | int encode_escape_forward_slash; |
| 176 | const char *encode_indent; | ||
| 175 | 177 | ||
| 176 | int decode_invalid_numbers; | 178 | int decode_invalid_numbers; |
| 177 | int decode_max_depth; | 179 | int decode_max_depth; |
| @@ -310,6 +312,18 @@ static int json_enum_option(lua_State *l, int optindex, int *setting, | |||
| 310 | return 1; | 312 | return 1; |
| 311 | } | 313 | } |
| 312 | 314 | ||
| 315 | /* Process string option for a configuration function */ | ||
| 316 | static int json_string_option(lua_State *l, int optindex, const char **setting) | ||
| 317 | { | ||
| 318 | if (!lua_isnil(l, optindex)) { | ||
| 319 | const char *value = luaL_checkstring(l, optindex); | ||
| 320 | *setting = value; | ||
| 321 | } | ||
| 322 | |||
| 323 | lua_pushstring(l, *setting ? *setting : ""); | ||
| 324 | return 1; | ||
| 325 | } | ||
| 326 | |||
| 313 | /* Configures handling of extremely sparse arrays: | 327 | /* Configures handling of extremely sparse arrays: |
| 314 | * convert: Convert extremely sparse arrays into objects? Otherwise error. | 328 | * convert: Convert extremely sparse arrays into objects? Otherwise error. |
| 315 | * ratio: 0: always allow sparse; 1: never allow sparse; >1: use ratio | 329 | * ratio: 0: always allow sparse; 1: never allow sparse; >1: use ratio |
| @@ -400,6 +414,18 @@ static int json_cfg_encode_keep_buffer(lua_State *l) | |||
| 400 | return 1; | 414 | return 1; |
| 401 | } | 415 | } |
| 402 | 416 | ||
| 417 | /* Configure how to indent output */ | ||
| 418 | static int json_cfg_encode_indent(lua_State *l) | ||
| 419 | { | ||
| 420 | json_config_t *cfg = json_arg_init(l, 1); | ||
| 421 | |||
| 422 | json_string_option(l, 1, &cfg->encode_indent); | ||
| 423 | /* simplify further checking */ | ||
| 424 | if (cfg->encode_indent[0] == '\0') cfg->encode_indent = NULL; | ||
| 425 | |||
| 426 | return 1; | ||
| 427 | } | ||
| 428 | |||
| 403 | #if defined(DISABLE_INVALID_NUMBERS) && !defined(USE_INTERNAL_FPCONV) | 429 | #if defined(DISABLE_INVALID_NUMBERS) && !defined(USE_INTERNAL_FPCONV) |
| 404 | void json_verify_invalid_number_setting(lua_State *l, int *setting) | 430 | void json_verify_invalid_number_setting(lua_State *l, int *setting) |
| 405 | { | 431 | { |
| @@ -491,6 +517,7 @@ static void json_create_config(lua_State *l) | |||
| 491 | cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; | 517 | cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; |
| 492 | cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH; | 518 | cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH; |
| 493 | cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES; | 519 | cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES; |
| 520 | cfg->encode_indent = DEFAULT_ENCODE_INDENT; | ||
| 494 | 521 | ||
| 495 | #if DEFAULT_ENCODE_KEEP_BUFFER > 0 | 522 | #if DEFAULT_ENCODE_KEEP_BUFFER > 0 |
| 496 | strbuf_init(&cfg->encode_buf, 0); | 523 | strbuf_init(&cfg->encode_buf, 0); |
| @@ -660,6 +687,13 @@ static void json_check_encode_depth(lua_State *l, json_config_t *cfg, | |||
| 660 | static int json_append_data(lua_State *l, json_config_t *cfg, | 687 | static int json_append_data(lua_State *l, json_config_t *cfg, |
| 661 | int current_depth, strbuf_t *json); | 688 | int current_depth, strbuf_t *json); |
| 662 | 689 | ||
| 690 | static void json_append_newline_and_indent(strbuf_t *json, json_config_t *cfg, int depth) | ||
| 691 | { | ||
| 692 | strbuf_append_char(json, '\n'); | ||
| 693 | for (int i = 0; i < depth; i++) | ||
| 694 | strbuf_append_string(json, cfg->encode_indent); | ||
| 695 | } | ||
| 696 | |||
| 663 | /* json_append_array args: | 697 | /* json_append_array args: |
| 664 | * - lua_State | 698 | * - lua_State |
| 665 | * - JSON strbuf | 699 | * - JSON strbuf |
| @@ -668,15 +702,21 @@ static void json_append_array(lua_State *l, json_config_t *cfg, int current_dept | |||
| 668 | strbuf_t *json, int array_length, int raw) | 702 | strbuf_t *json, int array_length, int raw) |
| 669 | { | 703 | { |
| 670 | int comma, i, json_pos, err; | 704 | int comma, i, json_pos, err; |
| 705 | int has_items = 0; | ||
| 671 | 706 | ||
| 672 | strbuf_append_char(json, '['); | 707 | strbuf_append_char(json, '['); |
| 673 | 708 | ||
| 674 | comma = 0; | 709 | comma = 0; |
| 675 | for (i = 1; i <= array_length; i++) { | 710 | for (i = 1; i <= array_length; i++) { |
| 711 | has_items = 1; | ||
| 712 | |||
| 676 | json_pos = strbuf_length(json); | 713 | json_pos = strbuf_length(json); |
| 677 | if (comma++ > 0) | 714 | if (comma++ > 0) |
| 678 | strbuf_append_char(json, ','); | 715 | strbuf_append_char(json, ','); |
| 679 | 716 | ||
| 717 | if (cfg->encode_indent) | ||
| 718 | json_append_newline_and_indent(json, cfg, current_depth); | ||
| 719 | |||
| 680 | if (raw) { | 720 | if (raw) { |
| 681 | lua_rawgeti(l, -1, i); | 721 | lua_rawgeti(l, -1, i); |
| 682 | } else { | 722 | } else { |
| @@ -698,6 +738,9 @@ static void json_append_array(lua_State *l, json_config_t *cfg, int current_dept | |||
| 698 | lua_pop(l, 1); | 738 | lua_pop(l, 1); |
| 699 | } | 739 | } |
| 700 | 740 | ||
| 741 | if (has_items && cfg->encode_indent) | ||
| 742 | json_append_newline_and_indent(json, cfg, current_depth-1); | ||
| 743 | |||
| 701 | strbuf_append_char(json, ']'); | 744 | strbuf_append_char(json, ']'); |
| 702 | } | 745 | } |
| 703 | 746 | ||
| @@ -752,6 +795,7 @@ static void json_append_object(lua_State *l, json_config_t *cfg, | |||
| 752 | int current_depth, strbuf_t *json) | 795 | int current_depth, strbuf_t *json) |
| 753 | { | 796 | { |
| 754 | int comma, keytype, json_pos, err; | 797 | int comma, keytype, json_pos, err; |
| 798 | int has_items = 0; | ||
| 755 | 799 | ||
| 756 | /* Object */ | 800 | /* Object */ |
| 757 | strbuf_append_char(json, '{'); | 801 | strbuf_append_char(json, '{'); |
| @@ -760,10 +804,15 @@ static void json_append_object(lua_State *l, json_config_t *cfg, | |||
| 760 | /* table, startkey */ | 804 | /* table, startkey */ |
| 761 | comma = 0; | 805 | comma = 0; |
| 762 | while (lua_next(l, -2) != 0) { | 806 | while (lua_next(l, -2) != 0) { |
| 807 | has_items = 1; | ||
| 808 | |||
| 763 | json_pos = strbuf_length(json); | 809 | json_pos = strbuf_length(json); |
| 764 | if (comma++ > 0) | 810 | if (comma++ > 0) |
| 765 | strbuf_append_char(json, ','); | 811 | strbuf_append_char(json, ','); |
| 766 | 812 | ||
| 813 | if (cfg->encode_indent) | ||
| 814 | json_append_newline_and_indent(json, cfg, current_depth); | ||
| 815 | |||
| 767 | /* table, key, value */ | 816 | /* table, key, value */ |
| 768 | keytype = lua_type(l, -2); | 817 | keytype = lua_type(l, -2); |
| 769 | if (keytype == LUA_TNUMBER) { | 818 | if (keytype == LUA_TNUMBER) { |
| @@ -778,6 +827,9 @@ static void json_append_object(lua_State *l, json_config_t *cfg, | |||
| 778 | "table key must be a number or string"); | 827 | "table key must be a number or string"); |
| 779 | /* never returns */ | 828 | /* never returns */ |
| 780 | } | 829 | } |
| 830 | if (cfg->encode_indent) | ||
| 831 | strbuf_append_char(json, ' '); | ||
| 832 | |||
| 781 | 833 | ||
| 782 | /* table, key, value */ | 834 | /* table, key, value */ |
| 783 | err = json_append_data(l, cfg, current_depth, json); | 835 | err = json_append_data(l, cfg, current_depth, json); |
| @@ -792,6 +844,9 @@ static void json_append_object(lua_State *l, json_config_t *cfg, | |||
| 792 | /* table, key */ | 844 | /* table, key */ |
| 793 | } | 845 | } |
| 794 | 846 | ||
| 847 | if (has_items && cfg->encode_indent) | ||
| 848 | json_append_newline_and_indent(json, cfg, current_depth-1); | ||
| 849 | |||
| 795 | strbuf_append_char(json, '}'); | 850 | strbuf_append_char(json, '}'); |
| 796 | } | 851 | } |
| 797 | 852 | ||
| @@ -1190,7 +1245,7 @@ static int json_is_invalid_number(json_parse_t *json) | |||
| 1190 | static void json_next_number_token(json_parse_t *json, json_token_t *token) | 1245 | static void json_next_number_token(json_parse_t *json, json_token_t *token) |
| 1191 | { | 1246 | { |
| 1192 | char *endptr; | 1247 | char *endptr; |
| 1193 | token->value.integer = strtoll(json->ptr, &endptr, 10); | 1248 | long long tmpval = strtoll(json->ptr, &endptr, 10); |
| 1194 | if (json->ptr == endptr || *endptr == '.' || *endptr == 'e' || | 1249 | if (json->ptr == endptr || *endptr == '.' || *endptr == 'e' || |
| 1195 | *endptr == 'E' || *endptr == 'x') { | 1250 | *endptr == 'E' || *endptr == 'x') { |
| 1196 | token->type = T_NUMBER; | 1251 | token->type = T_NUMBER; |
| @@ -1199,8 +1254,16 @@ static void json_next_number_token(json_parse_t *json, json_token_t *token) | |||
| 1199 | json_set_token_error(token, json, "invalid number"); | 1254 | json_set_token_error(token, json, "invalid number"); |
| 1200 | return; | 1255 | return; |
| 1201 | } | 1256 | } |
| 1257 | } else if (tmpval > PTRDIFF_MAX || tmpval < PTRDIFF_MIN) { | ||
| 1258 | /* Typical Lua builds typedef ptrdiff_t to lua_Integer. If tmpval is | ||
| 1259 | * outside the range of that type, we need to use T_NUMBER to avoid | ||
| 1260 | * truncation. | ||
| 1261 | */ | ||
| 1262 | token->type = T_NUMBER; | ||
| 1263 | token->value.number = tmpval; | ||
| 1202 | } else { | 1264 | } else { |
| 1203 | token->type = T_INTEGER; | 1265 | token->type = T_INTEGER; |
| 1266 | token->value.integer = tmpval; | ||
| 1204 | } | 1267 | } |
| 1205 | json->ptr = endptr; /* Skip the processed number */ | 1268 | json->ptr = endptr; /* Skip the processed number */ |
| 1206 | 1269 | ||
| @@ -1571,6 +1634,7 @@ static int lua_cjson_new(lua_State *l) | |||
| 1571 | { "decode_invalid_numbers", json_cfg_decode_invalid_numbers }, | 1634 | { "decode_invalid_numbers", json_cfg_decode_invalid_numbers }, |
| 1572 | { "encode_escape_forward_slash", json_cfg_encode_escape_forward_slash }, | 1635 | { "encode_escape_forward_slash", json_cfg_encode_escape_forward_slash }, |
| 1573 | { "encode_skip_unsupported_value_types", json_cfg_encode_skip_unsupported_value_types }, | 1636 | { "encode_skip_unsupported_value_types", json_cfg_encode_skip_unsupported_value_types }, |
| 1637 | { "encode_indent", json_cfg_encode_indent }, | ||
| 1574 | { "new", lua_cjson_new }, | 1638 | { "new", lua_cjson_new }, |
| 1575 | { NULL, NULL } | 1639 | { NULL, NULL } |
| 1576 | }; | 1640 | }; |
| @@ -85,8 +85,8 @@ strbuf_t *strbuf_new(size_t len) | |||
| 85 | static inline void debug_stats(strbuf_t *s) | 85 | static inline void debug_stats(strbuf_t *s) |
| 86 | { | 86 | { |
| 87 | if (s->debug) { | 87 | if (s->debug) { |
| 88 | fprintf(stderr, "strbuf(%lx) reallocs: %d, length: %zd, size: %zd\n", | 88 | fprintf(stderr, "strbuf(%p) reallocs: %d, length: %zd, size: %zd\n", |
| 89 | (long)s, s->reallocs, s->length, s->size); | 89 | s, s->reallocs, s->length, s->size); |
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -164,8 +164,8 @@ void strbuf_resize(strbuf_t *s, size_t len) | |||
| 164 | newsize = calculate_new_size(s, len); | 164 | newsize = calculate_new_size(s, len); |
| 165 | 165 | ||
| 166 | if (s->debug > 1) { | 166 | if (s->debug > 1) { |
| 167 | fprintf(stderr, "strbuf(%lx) resize: %zd => %zd\n", | 167 | fprintf(stderr, "strbuf(%p) resize: %zd => %zd\n", |
| 168 | (long)s, s->size, newsize); | 168 | s, s->size, newsize); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | s->size = newsize; | 171 | s->size = newsize; |
diff --git a/tests/test.lua b/tests/test.lua index cf7a54a..0513d97 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -333,6 +333,44 @@ local cjson_tests = { | |||
| 333 | json.decode, { [["\uDB00\uD"]] }, | 333 | json.decode, { [["\uDB00\uD"]] }, |
| 334 | false, { "Expected value but found invalid unicode escape code at character 2" } }, | 334 | false, { "Expected value but found invalid unicode escape code at character 2" } }, |
| 335 | 335 | ||
| 336 | -- Test indenting | ||
| 337 | { 'Set encode_indent(" ")', | ||
| 338 | json.encode_indent, { " " }, true, { " " } }, | ||
| 339 | { "Encode object with indenting", | ||
| 340 | json.encode, { { a = "a", b = "b" } }, | ||
| 341 | true, { | ||
| 342 | util.one_of { | ||
| 343 | '{\n "a": "a",\n "b": "b"\n}', | ||
| 344 | '{\n "b": "b",\n "a": "a"\n}', | ||
| 345 | } | ||
| 346 | } }, | ||
| 347 | { "Encode empty object with indenting", | ||
| 348 | json.encode, { { } }, true, { '{}' } }, | ||
| 349 | { "Encode nested object with indenting", | ||
| 350 | json.encode, { { a = { b = 1 } } }, | ||
| 351 | true, { '{\n "a": {\n "b": 1\n }\n}' } }, | ||
| 352 | { "Encode array with indenting", | ||
| 353 | json.encode, { { 1, 2, 3 } }, | ||
| 354 | true, { '[\n 1,\n 2,\n 3\n]' } }, | ||
| 355 | { "Encode empty array with indenting", | ||
| 356 | json.encode, { json.empty_array }, true, { '[]' } }, | ||
| 357 | { "Encode nested arrays with indenting", | ||
| 358 | json.encode, { { { 1, 2 }, { 3, 4 } } }, | ||
| 359 | true, { '[\n [\n 1,\n 2\n ],\n [\n 3,\n 4\n ]\n]' } }, | ||
| 360 | { "Encode array of objects with indenting", | ||
| 361 | json.encode, { { { a = "a" }, { b = "b" } } }, | ||
| 362 | true, { '[\n {\n "a": "a"\n },\n {\n "b": "b"\n }\n]' } }, | ||
| 363 | { 'Set encode_indent("abc")', | ||
| 364 | json.encode_indent, { "abc" }, true, { "abc" } }, | ||
| 365 | { "Encode object with non-whitespace indenting", | ||
| 366 | json.encode, { { a = { b = 1 } } }, | ||
| 367 | true, { '{\nabc"a": {\nabcabc"b": 1\nabc}\n}' } }, | ||
| 368 | { 'Set encode_indent("")', | ||
| 369 | json.encode_indent, { "" }, true, { "" } }, | ||
| 370 | { "Encode array of objects with empty indenting", | ||
| 371 | json.encode, { { { a = "a" }, { b = "b" } } }, | ||
| 372 | true, { '[{"a":"a"},{"b":"b"}]' } }, | ||
| 373 | |||
| 336 | -- Test locale support | 374 | -- Test locale support |
| 337 | -- | 375 | -- |
| 338 | -- The standard Lua interpreter is ANSI C online doesn't support locales | 376 | -- The standard Lua interpreter is ANSI C online doesn't support locales |
