diff options
Diffstat (limited to 'manual.txt')
-rw-r--r-- | manual.txt | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -173,6 +173,7 @@ Synopsis | |||
173 | -- Module instantiation | 173 | -- Module instantiation |
174 | local cjson = require "cjson" | 174 | local cjson = require "cjson" |
175 | local cjson2 = cjson.new() | 175 | local cjson2 = cjson.new() |
176 | local cjson_safe = require "cjson.safe" | ||
176 | 177 | ||
177 | -- Translate Lua value to/from JSON | 178 | -- Translate Lua value to/from JSON |
178 | text = cjson.encode(value) | 179 | text = cjson.encode(value) |
@@ -195,11 +196,20 @@ Module Instantiation | |||
195 | ------------ | 196 | ------------ |
196 | local cjson = require "cjson" | 197 | local cjson = require "cjson" |
197 | local cjson2 = cjson.new() | 198 | local cjson2 = cjson.new() |
199 | local cjson_safe = require "cjson.safe" | ||
198 | ------------ | 200 | ------------ |
199 | 201 | ||
200 | Import Lua CJSON via the Lua +require+ function. Lua CJSON does not | 202 | Import Lua CJSON via the Lua +require+ function. Lua CJSON does not |
201 | register a global module table with the default | 203 | register a global module table. |
202 | <<build_options,build options>>. | 204 | |
205 | The +cjson+ module will throw an error during JSON conversion if any | ||
206 | invalid data is encountered. Refer to <<cjson_encode,+cjson.encode+>> | ||
207 | and <<cjson_decode,+cjson.decode+>> for details. | ||
208 | |||
209 | The +cjson.safe+ module behaves identically to the +cjson+ module, | ||
210 | except 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 |
205 | CJSON module. The new module has a separate persistent encoding buffer, | 215 | CJSON 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 | ||
279 | Lua CJSON may throw an error when trying to decode numbers not supported | 289 | Lua CJSON may generate an error when trying to decode numbers not |
280 | by the JSON specification. _Invalid numbers_ are defined as: | 290 | supported 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 | ||
306 | Lua CJSON will throw an error when parsing deeply nested JSON once the | 316 | Lua CJSON will generate an error when parsing deeply nested JSON once |
307 | maximum array/object depth has been exceeded. This check prevents | 317 | the maximum array/object depth has been exceeded. This check prevents |
308 | unnecessarily complicated JSON from slowing down the application, or | 318 | unnecessarily complicated JSON from slowing down the application, or |
309 | crashing the application due to lack of process stack space. | 319 | crashing the application due to lack of process stack space. |
310 | 320 | ||
311 | An error may be thrown before the depth limit is hit if Lua is unable to | 321 | An error may be generated before the depth limit is hit if Lua is unable |
312 | allocate more objects on the Lua stack. | 322 | to allocate more objects on the Lua stack. |
313 | 323 | ||
314 | By default, Lua CJSON will reject JSON with arrays and/or objects nested | 324 | By default, Lua CJSON will reject JSON with arrays and/or objects nested |
315 | more than 1000 levels deep. | 325 | more 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 | ||
427 | Lua CJSON may throw an error when encoding floating point numbers not | 437 | Lua CJSON may generate an error when encoding floating point numbers not |
428 | supported by the JSON specification (_invalid numbers_): | 438 | supported 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 | ||
479 | Once the maximum table depth has been exceeded Lua CJSON will throw an | 489 | Once the maximum table depth has been exceeded Lua CJSON will generate |
480 | error. This prevents a deeply nested or recursive data structure from | 490 | an error. This prevents a deeply nested or recursive data structure from |
481 | crashing the application. | 491 | crashing the application. |
482 | 492 | ||
483 | By default, Lua CJSON will throw an error when trying to encode data | 493 | By default, Lua CJSON will generate an error when trying to encode data |
484 | structures with more than 1000 nested tables. | 494 | structures with more than 1000 nested tables. |
485 | 495 | ||
486 | The current setting is always returned, and is only updated when an | 496 | The current setting is always returned, and is only updated when an |