aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
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)