diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 37 |
1 files changed, 37 insertions, 0 deletions
| @@ -14,6 +14,7 @@ Table of Contents | |||
| 14 | * [array_mt](#array_mt) | 14 | * [array_mt](#array_mt) |
| 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 | * [decode_array_with_array_mt](#decode_array_with_array_mt) | ||
| 17 | 18 | ||
| 18 | Description | 19 | Description |
| 19 | =========== | 20 | =========== |
| @@ -156,3 +157,39 @@ encode_number_precision | |||
| 156 | This fork allows encoding of numbers with a `precision` up to 16 decimals (vs. 14 in mpx/lua-cjson). | 157 | This fork allows encoding of numbers with a `precision` up to 16 decimals (vs. 14 in mpx/lua-cjson). |
| 157 | 158 | ||
| 158 | [Back to TOC](#table-of-contents) | 159 | [Back to TOC](#table-of-contents) |
| 160 | |||
| 161 | decode_array_with_array_mt | ||
| 162 | -------------------------- | ||
| 163 | **syntax:** `cjson.decode_array_with_array_mt(enabled)` | ||
| 164 | |||
| 165 | **default:** false | ||
| 166 | |||
| 167 | If enabled, JSON Arrays decoded by `cjson.decode` will result in Lua | ||
| 168 | tables with the [`array_mt`](#array_mt) metatable. This can ensure a 1-to-1 | ||
| 169 | relationship between arrays upon multiple encoding/decoding of your | ||
| 170 | JSON data with this module. | ||
| 171 | |||
| 172 | If disabled, JSON Arrays will be decoded to plain Lua tables, without | ||
| 173 | the `array_mt` metatable. | ||
| 174 | |||
| 175 | The `enabled` argument is a boolean. | ||
| 176 | |||
| 177 | Example: | ||
| 178 | |||
| 179 | ```lua | ||
| 180 | local cjson = require "cjson" | ||
| 181 | |||
| 182 | -- default behavior | ||
| 183 | local my_json = [[{"my_array":[]}]] | ||
| 184 | local t = cjson.decode(my_json) | ||
| 185 | cjson.encode(t) -- {"my_array":{}} back to an object | ||
| 186 | |||
| 187 | -- now, if this behavior is enabled | ||
| 188 | cjson.decode_array_with_array_mt(true) | ||
| 189 | |||
| 190 | local my_json = [[{"my_array":[]}]] | ||
| 191 | local t = cjson.decode(my_json) | ||
| 192 | cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array | ||
| 193 | ``` | ||
| 194 | |||
| 195 | [Back to TOC](#table-of-contents) | ||
