aboutsummaryrefslogtreecommitdiff
path: root/manual.txt
diff options
context:
space:
mode:
Diffstat (limited to 'manual.txt')
-rw-r--r--manual.txt34
1 files changed, 22 insertions, 12 deletions
diff --git a/manual.txt b/manual.txt
index 9833c58..afd9528 100644
--- a/manual.txt
+++ b/manual.txt
@@ -173,6 +173,7 @@ Synopsis
173-- Module instantiation 173-- Module instantiation
174local cjson = require "cjson" 174local cjson = require "cjson"
175local cjson2 = cjson.new() 175local cjson2 = cjson.new()
176local cjson_safe = require "cjson.safe"
176 177
177-- Translate Lua value to/from JSON 178-- Translate Lua value to/from JSON
178text = cjson.encode(value) 179text = cjson.encode(value)
@@ -195,11 +196,20 @@ Module Instantiation
195------------ 196------------
196local cjson = require "cjson" 197local cjson = require "cjson"
197local cjson2 = cjson.new() 198local cjson2 = cjson.new()
199local cjson_safe = require "cjson.safe"
198------------ 200------------
199 201
200Import Lua CJSON via the Lua +require+ function. Lua CJSON does not 202Import Lua CJSON via the Lua +require+ function. Lua CJSON does not
201register a global module table with the default 203register a global module table.
202<<build_options,build options>>. 204
205The +cjson+ module will throw an error during JSON conversion if any
206invalid data is encountered. Refer to <<cjson_encode,+cjson.encode+>>
207and <<cjson_decode,+cjson.decode+>> for details.
208
209The +cjson.safe+ module behaves identically to the +cjson+ module,
210except when errors are encountered during JSON conversion. On error, the
211+cjson_safe.encode+ and +cjson_safe.decode+ functions will return
212+nil+ followed by the error message.
203 213
204+cjson.new+ can be used to instantiate an independent copy of the Lua 214+cjson.new+ can be used to instantiate an independent copy of the Lua
205CJSON module. The new module has a separate persistent encoding buffer, 215CJSON module. The new module has a separate persistent encoding buffer,
@@ -276,8 +286,8 @@ setting = cjson.decode_invalid_numbers([setting])
276-- "setting" must be a boolean. Default: true. 286-- "setting" must be a boolean. Default: true.
277------------ 287------------
278 288
279Lua CJSON may throw an error when trying to decode numbers not supported 289Lua CJSON may generate an error when trying to decode numbers not
280by the JSON specification. _Invalid numbers_ are defined as: 290supported by the JSON specification. _Invalid numbers_ are defined as:
281 291
282- infinity 292- infinity
283- not-a-number (NaN) 293- not-a-number (NaN)
@@ -303,13 +313,13 @@ depth = cjson.decode_max_depth([depth])
303-- "depth" must be a positive integer. Default: 1000. 313-- "depth" must be a positive integer. Default: 1000.
304------------ 314------------
305 315
306Lua CJSON will throw an error when parsing deeply nested JSON once the 316Lua CJSON will generate an error when parsing deeply nested JSON once
307maximum array/object depth has been exceeded. This check prevents 317the maximum array/object depth has been exceeded. This check prevents
308unnecessarily complicated JSON from slowing down the application, or 318unnecessarily complicated JSON from slowing down the application, or
309crashing the application due to lack of process stack space. 319crashing the application due to lack of process stack space.
310 320
311An error may be thrown before the depth limit is hit if Lua is unable to 321An error may be generated before the depth limit is hit if Lua is unable
312allocate more objects on the Lua stack. 322to allocate more objects on the Lua stack.
313 323
314By default, Lua CJSON will reject JSON with arrays and/or objects nested 324By default, Lua CJSON will reject JSON with arrays and/or objects nested
315more than 1000 levels deep. 325more than 1000 levels deep.
@@ -424,7 +434,7 @@ setting = cjson.encode_invalid_numbers([setting])
424-- "setting" must a boolean or "null". Default: false. 434-- "setting" must a boolean or "null". Default: false.
425------------ 435------------
426 436
427Lua CJSON may throw an error when encoding floating point numbers not 437Lua CJSON may generate an error when encoding floating point numbers not
428supported by the JSON specification (_invalid numbers_): 438supported by the JSON specification (_invalid numbers_):
429 439
430- infinity 440- infinity
@@ -476,11 +486,11 @@ depth = cjson.encode_max_depth([depth])
476-- "depth" must be a positive integer. Default: 1000. 486-- "depth" must be a positive integer. Default: 1000.
477------------ 487------------
478 488
479Once the maximum table depth has been exceeded Lua CJSON will throw an 489Once the maximum table depth has been exceeded Lua CJSON will generate
480error. This prevents a deeply nested or recursive data structure from 490an error. This prevents a deeply nested or recursive data structure from
481crashing the application. 491crashing the application.
482 492
483By default, Lua CJSON will throw an error when trying to encode data 493By default, Lua CJSON will generate an error when trying to encode data
484structures with more than 1000 nested tables. 494structures with more than 1000 nested tables.
485 495
486The current setting is always returned, and is only updated when an 496The current setting is always returned, and is only updated when an