… | |
… | |
86 | package JSON::XS; |
86 | package JSON::XS; |
87 | |
87 | |
88 | use strict; |
88 | use strict; |
89 | |
89 | |
90 | BEGIN { |
90 | BEGIN { |
91 | our $VERSION = '1.01'; |
91 | our $VERSION = '1.12'; |
92 | our @ISA = qw(Exporter); |
92 | our @ISA = qw(Exporter); |
93 | |
93 | |
94 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
94 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
95 | require Exporter; |
95 | require Exporter; |
96 | |
96 | |
… | |
… | |
154 | |
154 | |
155 | If C<$enable> is true (or missing), then the C<encode> method will not |
155 | If C<$enable> is true (or missing), then the C<encode> method will not |
156 | generate characters outside the code range C<0..127> (which is ASCII). Any |
156 | generate characters outside the code range C<0..127> (which is ASCII). Any |
157 | unicode characters outside that range will be escaped using either a |
157 | unicode characters outside that range will be escaped using either a |
158 | single \uXXXX (BMP characters) or a double \uHHHH\uLLLLL escape sequence, |
158 | single \uXXXX (BMP characters) or a double \uHHHH\uLLLLL escape sequence, |
159 | as per RFC4627. |
159 | as per RFC4627. The resulting encoded JSON text can be treated as a native |
|
|
160 | unicode string, an ascii-encoded, latin1-encoded or UTF-8 encoded string, |
|
|
161 | or any other superset of ASCII. |
160 | |
162 | |
161 | If C<$enable> is false, then the C<encode> method will not escape Unicode |
163 | If C<$enable> is false, then the C<encode> method will not escape Unicode |
162 | characters unless required by the JSON syntax. This results in a faster |
164 | characters unless required by the JSON syntax. This results in a faster |
163 | and more compact format. |
165 | and more compact format. |
164 | |
166 | |
… | |
… | |
309 | strings that look like integers or floats into integers or floats |
311 | strings that look like integers or floats into integers or floats |
310 | internally (there is no difference on the Perl level), saving space. |
312 | internally (there is no difference on the Perl level), saving space. |
311 | |
313 | |
312 | =item $json = $json->max_depth ([$maximum_nesting_depth]) |
314 | =item $json = $json->max_depth ([$maximum_nesting_depth]) |
313 | |
315 | |
314 | Sets the maximum nesting level (default C<4096>) accepted while encoding |
316 | Sets the maximum nesting level (default C<512>) accepted while encoding |
315 | or decoding. If the JSON text or Perl data structure has an equal or |
317 | or decoding. If the JSON text or Perl data structure has an equal or |
316 | higher nesting level then this limit, then the encoder and decoder will |
318 | higher nesting level then this limit, then the encoder and decoder will |
317 | stop and croak at that point. |
319 | stop and croak at that point. |
318 | |
320 | |
319 | Nesting level is defined by number of hash- or arrayrefs that the encoder |
321 | Nesting level is defined by number of hash- or arrayrefs that the encoder |
… | |
… | |
473 | $x *= 1; # same thing, the choise is yours. |
475 | $x *= 1; # same thing, the choise is yours. |
474 | |
476 | |
475 | You can not currently output JSON booleans or force the type in other, |
477 | You can not currently output JSON booleans or force the type in other, |
476 | less obscure, ways. Tell me if you need this capability. |
478 | less obscure, ways. Tell me if you need this capability. |
477 | |
479 | |
478 | =item circular data structures |
|
|
479 | |
|
|
480 | Those will be encoded until memory or stackspace runs out. |
|
|
481 | |
|
|
482 | =back |
480 | =back |
483 | |
481 | |
484 | |
482 | |
485 | =head1 COMPARISON |
483 | =head1 COMPARISON |
486 | |
484 | |
… | |
… | |
636 | usually a good indication of the size of the resources required to decode |
634 | usually a good indication of the size of the resources required to decode |
637 | it into a Perl structure. |
635 | it into a Perl structure. |
638 | |
636 | |
639 | Third, JSON::XS recurses using the C stack when decoding objects and |
637 | Third, JSON::XS recurses using the C stack when decoding objects and |
640 | arrays. The C stack is a limited resource: for instance, on my amd64 |
638 | arrays. The C stack is a limited resource: for instance, on my amd64 |
641 | machine with 8MB of stack size I can decode around 180k nested arrays |
639 | machine with 8MB of stack size I can decode around 180k nested arrays but |
642 | but only 14k nested JSON objects. If that is exceeded, the program |
640 | only 14k nested JSON objects (due to perl itself recursing deeply on croak |
643 | crashes. Thats why the default nesting limit is set to 4096. If your |
641 | to free the temporary). If that is exceeded, the program crashes. to be |
|
|
642 | conservative, the default nesting limit is set to 512. If your process |
644 | process has a smaller stack, you should adjust this setting accordingly |
643 | has a smaller stack, you should adjust this setting accordingly with the |
645 | with the C<max_depth> method. |
644 | C<max_depth> method. |
646 | |
645 | |
647 | And last but least, something else could bomb you that I forgot to think |
646 | And last but least, something else could bomb you that I forgot to think |
648 | of. In that case, you get to keep the pieces. I am alway sopen for hints, |
647 | of. In that case, you get to keep the pieces. I am always open for hints, |
649 | though... |
648 | though... |
650 | |
649 | |
651 | |
650 | |
652 | =head1 BUGS |
651 | =head1 BUGS |
653 | |
652 | |