aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorThibault Charbonnier <thibaultcha@me.com>2017-07-08 21:54:18 -0700
committerYichun Zhang (agentzh) <agentzh@gmail.com>2017-11-15 20:41:57 -0800
commit5f9efa4829a72935ddcd40c7da6b1a9e10939b65 (patch)
tree319cdf13f99c753f85820c3fabb89bfa50496dae /README.md
parenta9af7965219710ac1ec1e2bbf1a63eb77be622b7 (diff)
downloadlua-cjson-5f9efa4829a72935ddcd40c7da6b1a9e10939b65.tar.gz
lua-cjson-5f9efa4829a72935ddcd40c7da6b1a9e10939b65.tar.bz2
lua-cjson-5f9efa4829a72935ddcd40c7da6b1a9e10939b65.zip
feature: added new cjson.array_mt metatable to allow enforcing JSON array encoding.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
Diffstat (limited to 'README.md')
-rw-r--r--README.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/README.md b/README.md
index 7282a4d..1cdb53b 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ Table of Contents
11* [Additions to mpx/lua](#additions) 11* [Additions to mpx/lua](#additions)
12 * [encode_empty_table_as_object](#encode_empty_table_as_object) 12 * [encode_empty_table_as_object](#encode_empty_table_as_object)
13 * [empty_array](#empty_array) 13 * [empty_array](#empty_array)
14 * [array_mt](#array_mt)
14 * [empty_array_mt](#empty_array_mt) 15 * [empty_array_mt](#empty_array_mt)
15 * [encode_number_precision](#encode_number_precision) 16 * [encode_number_precision](#encode_number_precision)
16 17
@@ -76,6 +77,39 @@ This will generate:
76 77
77[Back to TOC](#table-of-contents) 78[Back to TOC](#table-of-contents)
78 79
80array_mt
81--------
82**syntax:** `setmetatable({}, cjson.array_mt)`
83
84When lua-cjson encodes a table with this metatable, it will systematically
85encode it as a JSON Array. The resulting, encoded Array will contain the array
86part of the table, and will be of the same length as the `#` operator on that
87table. Holes in the table will be encoded with the `null` JSON value.
88
89Example:
90
91```lua
92local t = { "hello", "world" }
93setmetatable(t, cjson.array_mt)
94cjson.encode(t) -- ["hello","world"]
95```
96
97Or:
98
99```lua
100local t = {}
101t[1] = "one"
102t[2] = "two"
103t[4] = "three"
104t.foo = "bar"
105setmetatable(t, cjson.array_mt)
106cjson.encode(t) -- ["one","two",null,"three"]
107```
108
109This value was introduced in the `2.1.0.5` release of this module.
110
111[Back to TOC](#table-of-contents)
112
79empty_array_mt 113empty_array_mt
80-------------- 114--------------
81**syntax:** `setmetatable({}, cjson.empty_array_mt)` 115**syntax:** `setmetatable({}, cjson.empty_array_mt)`