… | |
… | |
2 | JSON::XS - JSON serialising/deserialising, done correctly and fast |
2 | JSON::XS - JSON serialising/deserialising, done correctly and fast |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use JSON::XS; |
5 | use JSON::XS; |
6 | |
6 | |
7 | # exported functions, croak on error |
7 | # exported functions, they croak on error |
|
|
8 | # and expect/generate UTF-8 |
8 | |
9 | |
9 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
10 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
10 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
11 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
11 | |
12 | |
|
|
13 | # objToJson and jsonToObj aliases to to_json and from_json |
|
|
14 | # are exported for compatibility to the JSON module, |
|
|
15 | # but should not be used in new code. |
|
|
16 | |
12 | # oo-interface |
17 | # OO-interface |
13 | |
18 | |
14 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
19 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
15 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
20 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
16 | $perl_scalar = $coder->decode ($unicode_json_text); |
21 | $perl_scalar = $coder->decode ($unicode_json_text); |
17 | |
22 | |
… | |
… | |
30 | |
35 | |
31 | See MAPPING, below, on how JSON::XS maps perl values to JSON values and |
36 | See MAPPING, below, on how JSON::XS maps perl values to JSON values and |
32 | vice versa. |
37 | vice versa. |
33 | |
38 | |
34 | FEATURES |
39 | FEATURES |
35 | * correct handling of unicode issues |
40 | * correct unicode handling |
36 | This module knows how to handle Unicode, and even documents how and |
41 | This module knows how to handle Unicode, and even documents how and |
37 | when it does so. |
42 | when it does so. |
38 | |
43 | |
39 | * round-trip integrity |
44 | * round-trip integrity |
40 | When you serialise a perl data structure using only datatypes |
45 | When you serialise a perl data structure using only datatypes |
41 | supported by JSON, the deserialised data structure is identical on |
46 | supported by JSON, the deserialised data structure is identical on |
42 | the Perl level. (e.g. the string "2.0" doesn't suddenly become "2"). |
47 | the Perl level. (e.g. the string "2.0" doesn't suddenly become "2" |
|
|
48 | just because it looks like a number). |
43 | |
49 | |
44 | * strict checking of JSON correctness |
50 | * strict checking of JSON correctness |
45 | There is no guessing, no generating of illegal JSON texts by |
51 | There is no guessing, no generating of illegal JSON texts by |
46 | default, and only JSON is accepted as input by default (the latter |
52 | default, and only JSON is accepted as input by default (the latter |
47 | is a security feature). |
53 | is a security feature). |
… | |
… | |
55 | interface. |
61 | interface. |
56 | |
62 | |
57 | * reasonably versatile output formats |
63 | * reasonably versatile output formats |
58 | You can choose between the most compact guarenteed single-line |
64 | You can choose between the most compact guarenteed single-line |
59 | format possible (nice for simple line-based protocols), a pure-ascii |
65 | format possible (nice for simple line-based protocols), a pure-ascii |
60 | format (for when your transport is not 8-bit clean), or a |
66 | format (for when your transport is not 8-bit clean, still supports |
61 | pretty-printed format (for when you want to read that stuff). Or you |
67 | the whole unicode range), or a pretty-printed format (for when you |
62 | can combine those features in whatever way you like. |
68 | want to read that stuff). Or you can combine those features in |
|
|
69 | whatever way you like. |
63 | |
70 | |
64 | FUNCTIONAL INTERFACE |
71 | FUNCTIONAL INTERFACE |
65 | The following convinience methods are provided by this module. They are |
72 | The following convinience methods are provided by this module. They are |
66 | exported by default: |
73 | exported by default: |
67 | |
74 | |
… | |
… | |
105 | $json = $json->ascii ([$enable]) |
112 | $json = $json->ascii ([$enable]) |
106 | If $enable is true (or missing), then the "encode" method will not |
113 | If $enable is true (or missing), then the "encode" method will not |
107 | generate characters outside the code range 0..127 (which is ASCII). |
114 | generate characters outside the code range 0..127 (which is ASCII). |
108 | Any unicode characters outside that range will be escaped using |
115 | Any unicode characters outside that range will be escaped using |
109 | either a single \uXXXX (BMP characters) or a double \uHHHH\uLLLLL |
116 | either a single \uXXXX (BMP characters) or a double \uHHHH\uLLLLL |
110 | escape sequence, as per RFC4627. |
117 | escape sequence, as per RFC4627. The resulting encoded JSON text can |
|
|
118 | be treated as a native unicode string, an ascii-encoded, |
|
|
119 | latin1-encoded or UTF-8 encoded string, or any other superset of |
|
|
120 | ASCII. |
111 | |
121 | |
112 | If $enable is false, then the "encode" method will not escape |
122 | If $enable is false, then the "encode" method will not escape |
113 | Unicode characters unless required by the JSON syntax. This results |
123 | Unicode characters unless required by the JSON syntax or other |
114 | in a faster and more compact format. |
124 | flags. This results in a faster and more compact format. |
|
|
125 | |
|
|
126 | The main use for this flag is to produce JSON texts that can be |
|
|
127 | transmitted over a 7-bit channel, as the encoded JSON texts will not |
|
|
128 | contain any 8 bit characters. |
115 | |
129 | |
116 | JSON::XS->new->ascii (1)->encode ([chr 0x10401]) |
130 | JSON::XS->new->ascii (1)->encode ([chr 0x10401]) |
117 | => ["\ud801\udc01"] |
131 | => ["\ud801\udc01"] |
|
|
132 | |
|
|
133 | $json = $json->latin1 ([$enable]) |
|
|
134 | If $enable is true (or missing), then the "encode" method will |
|
|
135 | encode the resulting JSON text as latin1 (or iso-8859-1), escaping |
|
|
136 | any characters outside the code range 0..255. The resulting string |
|
|
137 | can be treated as a latin1-encoded JSON text or a native unicode |
|
|
138 | string. The "decode" method will not be affected in any way by this |
|
|
139 | flag, as "decode" by default expects unicode, which is a strict |
|
|
140 | superset of latin1. |
|
|
141 | |
|
|
142 | If $enable is false, then the "encode" method will not escape |
|
|
143 | Unicode characters unless required by the JSON syntax or other |
|
|
144 | flags. |
|
|
145 | |
|
|
146 | The main use for this flag is efficiently encoding binary data as |
|
|
147 | JSON text, as most octets will not be escaped, resulting in a |
|
|
148 | smaller encoded size. The disadvantage is that the resulting JSON |
|
|
149 | text is encoded in latin1 (and must correctly be treated as such |
|
|
150 | when storing and transfering), a rare encoding for JSON. It is |
|
|
151 | therefore most useful when you want to store data structures known |
|
|
152 | to contain binary data efficiently in files or databases, not when |
|
|
153 | talking to other JSON encoders/decoders. |
|
|
154 | |
|
|
155 | JSON::XS->new->latin1->encode (["\x{89}\x{abc}"] |
|
|
156 | => ["\x{89}\\u0abc"] # (perl syntax, U+abc escaped, U+89 not) |
118 | |
157 | |
119 | $json = $json->utf8 ([$enable]) |
158 | $json = $json->utf8 ([$enable]) |
120 | If $enable is true (or missing), then the "encode" method will |
159 | If $enable is true (or missing), then the "encode" method will |
121 | encode the JSON result into UTF-8, as required by many protocols, |
160 | encode the JSON result into UTF-8, as required by many protocols, |
122 | while the "decode" method expects to be handled an UTF-8-encoded |
161 | while the "decode" method expects to be handled an UTF-8-encoded |
… | |
… | |
238 | "encode" or "decode" to their minimum size possible. This can save |
277 | "encode" or "decode" to their minimum size possible. This can save |
239 | memory when your JSON texts are either very very long or you have |
278 | memory when your JSON texts are either very very long or you have |
240 | many short strings. It will also try to downgrade any strings to |
279 | many short strings. It will also try to downgrade any strings to |
241 | octet-form if possible: perl stores strings internally either in an |
280 | octet-form if possible: perl stores strings internally either in an |
242 | encoding called UTF-X or in octet-form. The latter cannot store |
281 | encoding called UTF-X or in octet-form. The latter cannot store |
243 | everything but uses less space in general. |
282 | everything but uses less space in general (and some buggy Perl or C |
|
|
283 | code might even rely on that internal representation being used). |
|
|
284 | |
|
|
285 | The actual definition of what shrink does might change in future |
|
|
286 | versions, but it will always try to save space at the expense of |
|
|
287 | time. |
244 | |
288 | |
245 | If $enable is true (or missing), the string returned by "encode" |
289 | If $enable is true (or missing), the string returned by "encode" |
246 | will be shrunk-to-fit, while all strings generated by "decode" will |
290 | will be shrunk-to-fit, while all strings generated by "decode" will |
247 | also be shrunk-to-fit. |
291 | also be shrunk-to-fit. |
248 | |
292 | |
… | |
… | |
251 | |
295 | |
252 | In the future, this setting might control other things, such as |
296 | In the future, this setting might control other things, such as |
253 | converting strings that look like integers or floats into integers |
297 | converting strings that look like integers or floats into integers |
254 | or floats internally (there is no difference on the Perl level), |
298 | or floats internally (there is no difference on the Perl level), |
255 | saving space. |
299 | saving space. |
|
|
300 | |
|
|
301 | $json = $json->max_depth ([$maximum_nesting_depth]) |
|
|
302 | Sets the maximum nesting level (default 512) accepted while encoding |
|
|
303 | or decoding. If the JSON text or Perl data structure has an equal or |
|
|
304 | higher nesting level then this limit, then the encoder and decoder |
|
|
305 | will stop and croak at that point. |
|
|
306 | |
|
|
307 | Nesting level is defined by number of hash- or arrayrefs that the |
|
|
308 | encoder needs to traverse to reach a given point or the number of |
|
|
309 | "{" or "[" characters without their matching closing parenthesis |
|
|
310 | crossed to reach a given character in a string. |
|
|
311 | |
|
|
312 | Setting the maximum depth to one disallows any nesting, so that |
|
|
313 | ensures that the object is only a single hash/object or array. |
|
|
314 | |
|
|
315 | The argument to "max_depth" will be rounded up to the next nearest |
|
|
316 | power of two. |
|
|
317 | |
|
|
318 | See SECURITY CONSIDERATIONS, below, for more info on why this is |
|
|
319 | useful. |
256 | |
320 | |
257 | $json_text = $json->encode ($perl_scalar) |
321 | $json_text = $json->encode ($perl_scalar) |
258 | Converts the given Perl data structure (a simple scalar or a |
322 | Converts the given Perl data structure (a simple scalar or a |
259 | reference to a hash or array) to its JSON representation. Simple |
323 | reference to a hash or array) to its JSON representation. Simple |
260 | scalars will be converted into JSON string or number sequences, |
324 | scalars will be converted into JSON string or number sequences, |
… | |
… | |
269 | |
333 | |
270 | JSON numbers and strings become simple Perl scalars. JSON arrays |
334 | JSON numbers and strings become simple Perl scalars. JSON arrays |
271 | become Perl arrayrefs and JSON objects become Perl hashrefs. "true" |
335 | become Perl arrayrefs and JSON objects become Perl hashrefs. "true" |
272 | becomes 1, "false" becomes 0 and "null" becomes "undef". |
336 | becomes 1, "false" becomes 0 and "null" becomes "undef". |
273 | |
337 | |
|
|
338 | ($perl_scalar, $characters) = $json->decode_prefix ($json_text) |
|
|
339 | This works like the "decode" method, but instead of raising an |
|
|
340 | exception when there is trailing garbage after the first JSON |
|
|
341 | object, it will silently stop parsing there and return the number of |
|
|
342 | characters consumed so far. |
|
|
343 | |
|
|
344 | This is useful if your JSON texts are not delimited by an outer |
|
|
345 | protocol (which is not the brightest thing to do in the first place) |
|
|
346 | and you need to know where the JSON text ends. |
|
|
347 | |
|
|
348 | JSON::XS->new->decode_prefix ("[1] the tail") |
|
|
349 | => ([], 3) |
|
|
350 | |
274 | MAPPING |
351 | MAPPING |
275 | This section describes how JSON::XS maps Perl values to JSON values and |
352 | This section describes how JSON::XS maps Perl values to JSON values and |
276 | vice versa. These mappings are designed to "do the right thing" in most |
353 | vice versa. These mappings are designed to "do the right thing" in most |
277 | circumstances automatically, preserving round-tripping characteristics |
354 | circumstances automatically, preserving round-tripping characteristics |
278 | (what you put in comes out as something equivalent). |
355 | (what you put in comes out as something equivalent). |
… | |
… | |
317 | truly typeless language, so we can only guess which JSON type is meant |
394 | truly typeless language, so we can only guess which JSON type is meant |
318 | by a Perl value. |
395 | by a Perl value. |
319 | |
396 | |
320 | hash references |
397 | hash references |
321 | Perl hash references become JSON objects. As there is no inherent |
398 | Perl hash references become JSON objects. As there is no inherent |
322 | ordering in hash keys, they will usually be encoded in a |
399 | ordering in hash keys (or JSON objects), they will usually be |
323 | pseudo-random order that can change between runs of the same program |
400 | encoded in a pseudo-random order that can change between runs of the |
324 | but stays generally the same within a single run of a program. |
401 | same program but stays generally the same within a single run of a |
325 | JSON::XS can optionally sort the hash keys (determined by the |
402 | program. JSON::XS can optionally sort the hash keys (determined by |
326 | *canonical* flag), so the same datastructure will serialise to the |
403 | the *canonical* flag), so the same datastructure will serialise to |
327 | same JSON text (given same settings and version of JSON::XS), but |
404 | the same JSON text (given same settings and version of JSON::XS), |
328 | this incurs a runtime overhead. |
405 | but this incurs a runtime overhead and is only rarely useful, e.g. |
|
|
406 | when you want to compare some JSON text against another for |
|
|
407 | equality. |
329 | |
408 | |
330 | array references |
409 | array references |
331 | Perl array references become JSON arrays. |
410 | Perl array references become JSON arrays. |
|
|
411 | |
|
|
412 | other references |
|
|
413 | Other unblessed references are generally not allowed and will cause |
|
|
414 | an exception to be thrown, except for references to the integers 0 |
|
|
415 | and 1, which get turned into "false" and "true" atoms in JSON. You |
|
|
416 | can also use "JSON::XS::false" and "JSON::XS::true" to improve |
|
|
417 | readability. |
|
|
418 | |
|
|
419 | to_json [\0,JSON::XS::true] # yields [false,true] |
332 | |
420 | |
333 | blessed objects |
421 | blessed objects |
334 | Blessed objects are not allowed. JSON::XS currently tries to encode |
422 | Blessed objects are not allowed. JSON::XS currently tries to encode |
335 | their underlying representation (hash- or arrayref), but this |
423 | their underlying representation (hash- or arrayref), but this |
336 | behaviour might change in future versions. |
424 | behaviour might change in future versions. |
… | |
… | |
367 | $x += 0; # numify it, ensuring it will be dumped as a number |
455 | $x += 0; # numify it, ensuring it will be dumped as a number |
368 | $x *= 1; # same thing, the choise is yours. |
456 | $x *= 1; # same thing, the choise is yours. |
369 | |
457 | |
370 | You can not currently output JSON booleans or force the type in |
458 | You can not currently output JSON booleans or force the type in |
371 | other, less obscure, ways. Tell me if you need this capability. |
459 | other, less obscure, ways. Tell me if you need this capability. |
372 | |
|
|
373 | circular data structures |
|
|
374 | Those will be encoded until memory or stackspace runs out. |
|
|
375 | |
460 | |
376 | COMPARISON |
461 | COMPARISON |
377 | As already mentioned, this module was created because none of the |
462 | As already mentioned, this module was created because none of the |
378 | existing JSON modules could be made to work correctly. First I will |
463 | existing JSON modules could be made to work correctly. First I will |
379 | describe the problems (or pleasures) I encountered with various existing |
464 | describe the problems (or pleasures) I encountered with various existing |
… | |
… | |
450 | Does not generate valid JSON texts (key strings are often unquoted, |
535 | Does not generate valid JSON texts (key strings are often unquoted, |
451 | empty keys result in nothing being output) |
536 | empty keys result in nothing being output) |
452 | |
537 | |
453 | Does not check input for validity. |
538 | Does not check input for validity. |
454 | |
539 | |
|
|
540 | JSON and YAML |
|
|
541 | You often hear that JSON is a subset (or a close subset) of YAML. This |
|
|
542 | is, however, a mass hysteria and very far from the truth. In general, |
|
|
543 | there is no way to configure JSON::XS to output a data structure as |
|
|
544 | valid YAML. |
|
|
545 | |
|
|
546 | If you really must use JSON::XS to generate YAML, you should use this |
|
|
547 | algorithm (subject to change in future versions): |
|
|
548 | |
|
|
549 | my $to_yaml = JSON::XS->new->utf8->space_after (1); |
|
|
550 | my $yaml = $to_yaml->encode ($ref) . "\n"; |
|
|
551 | |
|
|
552 | This will usually generate JSON texts that also parse as valid YAML. |
|
|
553 | Please note that YAML has hardcoded limits on (simple) object key |
|
|
554 | lengths that JSON doesn't have, so you should make sure that your hash |
|
|
555 | keys are noticably shorter than the 1024 characters YAML allows. |
|
|
556 | |
|
|
557 | There might be other incompatibilities that I am not aware of. In |
|
|
558 | general you should not try to generate YAML with a JSON generator or |
|
|
559 | vice versa, or try to parse JSON with a YAML parser or vice versa: |
|
|
560 | chances are high that you will run into severe interoperability |
|
|
561 | problems. |
|
|
562 | |
455 | SPEED |
563 | SPEED |
456 | It seems that JSON::XS is surprisingly fast, as shown in the following |
564 | It seems that JSON::XS is surprisingly fast, as shown in the following |
457 | tables. They have been generated with the help of the "eg/bench" program |
565 | tables. They have been generated with the help of the "eg/bench" program |
458 | in the JSON::XS distribution, to make it easy to compare on your own |
566 | in the JSON::XS distribution, to make it easy to compare on your own |
459 | system. |
567 | system. |
460 | |
568 | |
461 | First comes a comparison between various modules using a very short JSON |
569 | First comes a comparison between various modules using a very short |
462 | string: |
570 | single-line JSON string: |
463 | |
571 | |
464 | {"method": "handleMessage", "params": ["user1", "we were just talking"], "id": null} |
572 | {"method": "handleMessage", "params": ["user1", "we were just talking"], \ |
|
|
573 | "id": null, "array":[1,11,234,-5,1e5,1e7, true, false]} |
465 | |
574 | |
466 | It shows the number of encodes/decodes per second (JSON::XS uses the |
575 | It shows the number of encodes/decodes per second (JSON::XS uses the |
467 | functional interface, while JSON::XS/2 uses the OO interface with |
576 | functional interface, while JSON::XS/2 uses the OO interface with |
468 | pretty-printing and hashkey sorting enabled). Higher is better: |
577 | pretty-printing and hashkey sorting enabled, JSON::XS/3 enables shrink). |
|
|
578 | Higher is better: |
469 | |
579 | |
470 | module | encode | decode | |
580 | module | encode | decode | |
471 | -----------|------------|------------| |
581 | -----------|------------|------------| |
472 | JSON | 11488.516 | 7823.035 | |
582 | JSON | 7645.468 | 4208.613 | |
473 | JSON::DWIW | 94708.054 | 129094.260 | |
583 | JSON::DWIW | 40721.398 | 77101.176 | |
474 | JSON::PC | 63884.157 | 128528.212 | |
584 | JSON::PC | 65948.176 | 78251.940 | |
475 | JSON::Syck | 34898.677 | 42096.911 | |
585 | JSON::Syck | 22844.793 | 26479.192 | |
476 | JSON::XS | 654027.064 | 396423.669 | |
586 | JSON::XS | 388361.481 | 199728.762 | |
477 | JSON::XS/2 | 371564.190 | 371725.613 | |
587 | JSON::XS/2 | 218453.333 | 192399.266 | |
|
|
588 | JSON::XS/3 | 338250.323 | 192399.266 | |
|
|
589 | Storable | 15779.925 | 14169.946 | |
478 | -----------+------------+------------+ |
590 | -----------+------------+------------+ |
479 | |
591 | |
480 | That is, JSON::XS is more than six times faster than JSON::DWIW on |
592 | That is, JSON::XS is about five times faster than JSON::DWIW on |
481 | encoding, more than three times faster on decoding, and about thirty |
593 | encoding, about three times faster on decoding, and over fourty times |
482 | times faster than JSON, even with pretty-printing and key sorting. |
594 | faster than JSON, even with pretty-printing and key sorting. It also |
|
|
595 | compares favourably to Storable for small amounts of data. |
483 | |
596 | |
484 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
597 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
485 | search API (http://nanoref.com/yahooapis/mgPdGg): |
598 | search API (http://nanoref.com/yahooapis/mgPdGg): |
486 | |
599 | |
487 | module | encode | decode | |
600 | module | encode | decode | |
488 | -----------|------------|------------| |
601 | -----------|------------|------------| |
489 | JSON | 273.023 | 44.674 | |
602 | JSON | 254.685 | 37.665 | |
490 | JSON::DWIW | 1089.383 | 1145.704 | |
603 | JSON::DWIW | 843.343 | 1049.731 | |
491 | JSON::PC | 3097.419 | 2393.921 | |
604 | JSON::PC | 3602.116 | 2307.352 | |
492 | JSON::Syck | 514.060 | 843.053 | |
605 | JSON::Syck | 505.107 | 787.899 | |
493 | JSON::XS | 6479.668 | 3636.364 | |
606 | JSON::XS | 5747.196 | 3690.220 | |
494 | JSON::XS/2 | 3774.221 | 3599.124 | |
607 | JSON::XS/2 | 3968.121 | 3676.634 | |
|
|
608 | JSON::XS/3 | 6105.246 | 3662.508 | |
|
|
609 | Storable | 4417.337 | 5285.161 | |
495 | -----------+------------+------------+ |
610 | -----------+------------+------------+ |
496 | |
611 | |
497 | Again, JSON::XS leads by far. |
612 | Again, JSON::XS leads by far (except for Storable which non-surprisingly |
|
|
613 | decodes faster). |
498 | |
614 | |
499 | On large strings containing lots of high unicode characters, some |
615 | On large strings containing lots of high unicode characters, some |
500 | modules (such as JSON::PC) seem to decode faster than JSON::XS, but the |
616 | modules (such as JSON::PC) seem to decode faster than JSON::XS, but the |
501 | result will be broken due to missing (or wrong) unicode handling. Others |
617 | result will be broken due to missing (or wrong) unicode handling. Others |
502 | refuse to decode or encode properly, so it was impossible to prepare a |
618 | refuse to decode or encode properly, so it was impossible to prepare a |
503 | fair comparison table for that case. |
619 | fair comparison table for that case. |
504 | |
620 | |
505 | RESOURCE LIMITS |
621 | SECURITY CONSIDERATIONS |
506 | JSON::XS does not impose any limits on the size of JSON texts or Perl |
622 | When you are using JSON in a protocol, talking to untrusted potentially |
507 | values they represent - if your machine can handle it, JSON::XS will |
623 | hostile creatures requires relatively few measures. |
508 | encode or decode it. Future versions might optionally impose structure |
624 | |
509 | depth and memory use resource limits. |
625 | First of all, your JSON decoder should be secure, that is, should not |
|
|
626 | have any buffer overflows. Obviously, this module should ensure that and |
|
|
627 | I am trying hard on making that true, but you never know. |
|
|
628 | |
|
|
629 | Second, you need to avoid resource-starving attacks. That means you |
|
|
630 | should limit the size of JSON texts you accept, or make sure then when |
|
|
631 | your resources run out, thats just fine (e.g. by using a separate |
|
|
632 | process that can crash safely). The size of a JSON text in octets or |
|
|
633 | characters is usually a good indication of the size of the resources |
|
|
634 | required to decode it into a Perl structure. |
|
|
635 | |
|
|
636 | Third, JSON::XS recurses using the C stack when decoding objects and |
|
|
637 | arrays. The C stack is a limited resource: for instance, on my amd64 |
|
|
638 | machine with 8MB of stack size I can decode around 180k nested arrays |
|
|
639 | but only 14k nested JSON objects (due to perl itself recursing deeply on |
|
|
640 | croak to free the temporary). If that is exceeded, the program crashes. |
|
|
641 | to be conservative, the default nesting limit is set to 512. If your |
|
|
642 | process has a smaller stack, you should adjust this setting accordingly |
|
|
643 | with the "max_depth" method. |
|
|
644 | |
|
|
645 | And last but least, something else could bomb you that I forgot to think |
|
|
646 | of. In that case, you get to keep the pieces. I am always open for |
|
|
647 | hints, though... |
510 | |
648 | |
511 | BUGS |
649 | BUGS |
512 | While the goal of this module is to be correct, that unfortunately does |
650 | While the goal of this module is to be correct, that unfortunately does |
513 | not mean its bug-free, only that I think its design is bug-free. It is |
651 | not mean its bug-free, only that I think its design is bug-free. It is |
514 | still very young and not well-tested. If you keep reporting bugs they |
652 | still relatively early in its development. If you keep reporting bugs |
515 | will be fixed swiftly, though. |
653 | they will be fixed swiftly, though. |
516 | |
654 | |
517 | AUTHOR |
655 | AUTHOR |
518 | Marc Lehmann <schmorp@schmorp.de> |
656 | Marc Lehmann <schmorp@schmorp.de> |
519 | http://home.schmorp.de/ |
657 | http://home.schmorp.de/ |
520 | |
658 | |