aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorThibault Charbonnier <thibaultcha@me.com>2017-08-05 15:19:43 -0700
committerYichun Zhang (agentzh) <agentzh@gmail.com>2017-11-17 11:46:46 -0800
commitb5e364c7c60167995944ed3a3b9c54d9a377fc1d (patch)
treeb2554317191a34b155aca68be0a54ef364296b58 /README.md
parent5f9efa4829a72935ddcd40c7da6b1a9e10939b65 (diff)
downloadlua-cjson-2.1.0.6rc1.tar.gz
lua-cjson-2.1.0.6rc1.tar.bz2
lua-cjson-2.1.0.6rc1.zip
feature: set cjson.array_mt on decoded JSON arrays.2.1.0.6rc1
this can be turned on via cjson.decode_array_with_array_mt(true). off by default. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
Diffstat (limited to 'README.md')
-rw-r--r--README.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1cdb53b..83bfd76 100644
--- a/README.md
+++ b/README.md
@@ -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
18Description 19Description
19=========== 20===========
@@ -156,3 +157,39 @@ encode_number_precision
156This fork allows encoding of numbers with a `precision` up to 16 decimals (vs. 14 in mpx/lua-cjson). 157This 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
161decode_array_with_array_mt
162--------------------------
163**syntax:** `cjson.decode_array_with_array_mt(enabled)`
164
165**default:** false
166
167If enabled, JSON Arrays decoded by `cjson.decode` will result in Lua
168tables with the [`array_mt`](#array_mt) metatable. This can ensure a 1-to-1
169relationship between arrays upon multiple encoding/decoding of your
170JSON data with this module.
171
172If disabled, JSON Arrays will be decoded to plain Lua tables, without
173the `array_mt` metatable.
174
175The `enabled` argument is a boolean.
176
177Example:
178
179```lua
180local cjson = require "cjson"
181
182-- default behavior
183local my_json = [[{"my_array":[]}]]
184local t = cjson.decode(my_json)
185cjson.encode(t) -- {"my_array":{}} back to an object
186
187-- now, if this behavior is enabled
188cjson.decode_array_with_array_mt(true)
189
190local my_json = [[{"my_array":[]}]]
191local t = cjson.decode(my_json)
192cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array
193```
194
195[Back to TOC](#table-of-contents)