--- JSON-XS/XS.pm 2007/03/25 21:19:13 1.23 +++ JSON-XS/XS.pm 2007/04/09 05:09:57 1.29 @@ -88,7 +88,7 @@ use strict; BEGIN { - our $VERSION = '0.8'; + our $VERSION = '1.11'; our @ISA = qw(Exporter); our @EXPORT = qw(to_json from_json objToJson jsonToObj); @@ -286,16 +286,21 @@ =item $json = $json->shrink ([$enable]) Perl usually over-allocates memory a bit when allocating space for -strings. This flag optionally resizes strings generated by either +strings. This flag optionally resizes strings generated by either C or C to their minimum size possible. This can save memory when your JSON texts are either very very long or you have many short strings. It will also try to downgrade any strings to octet-form if possible: perl stores strings internally either in an encoding called UTF-X or in octet-form. The latter cannot store everything but uses less -space in general. +space in general (and some buggy Perl or C code might even rely on that +internal representation being used). -If C<$enable> is true (or missing), the string returned by C will be shrunk-to-fit, -while all strings generated by C will also be shrunk-to-fit. +The actual definition of what shrink does might change in future versions, +but it will always try to save space at the expense of time. + +If C<$enable> is true (or missing), the string returned by C will +be shrunk-to-fit, while all strings generated by C will also be +shrunk-to-fit. If C<$enable> is false, then the normal perl allocation algorithms are used. If you work with your data, then this is likely to be faster. @@ -306,7 +311,7 @@ =item $json = $json->max_depth ([$maximum_nesting_depth]) -Sets the maximum nesting level (default C<8192>) accepted while encoding +Sets the maximum nesting level (default C<512>) accepted while encoding or decoding. If the JSON text or Perl data structure has an equal or higher nesting level then this limit, then the encoder and decoder will stop and croak at that point. @@ -407,17 +412,28 @@ =item hash references Perl hash references become JSON objects. As there is no inherent ordering -in hash keys, they will usually be encoded in a pseudo-random order that -can change between runs of the same program but stays generally the same -within a single run of a program. JSON::XS can optionally sort the hash -keys (determined by the I flag), so the same datastructure -will serialise to the same JSON text (given same settings and version of -JSON::XS), but this incurs a runtime overhead. +in hash keys (or JSON objects), they will usually be encoded in a +pseudo-random order that can change between runs of the same program but +stays generally the same within a single run of a program. JSON::XS can +optionally sort the hash keys (determined by the I flag), so +the same datastructure will serialise to the same JSON text (given same +settings and version of JSON::XS), but this incurs a runtime overhead +and is only rarely useful, e.g. when you want to compare some JSON text +against another for equality. =item array references Perl array references become JSON arrays. +=item other references + +Other unblessed references are generally not allowed and will cause an +exception to be thrown, except for references to the integers C<0> and +C<1>, which get turned into C and C atoms in JSON. You can +also use C and C to improve readability. + + to_json [\0,JSON::XS::true] # yields [false,true] + =item blessed objects Blessed objects are not allowed. JSON::XS currently tries to encode their @@ -459,10 +475,6 @@ You can not currently output JSON booleans or force the type in other, less obscure, ways. Tell me if you need this capability. -=item circular data structures - -Those will be encoded until memory or stackspace runs out. - =back @@ -622,11 +634,12 @@ Third, JSON::XS recurses using the C stack when decoding objects and arrays. The C stack is a limited resource: for instance, on my amd64 -machine with 8MB of stack size I can decode around 180k nested arrays -but only 14k nested JSON objects. If that is exceeded, the program -crashes. Thats why the default nesting limit is set to 8192. If your -process has a smaller stack, you should adjust this setting accordingly -with the C method. +machine with 8MB of stack size I can decode around 180k nested arrays but +only 14k nested JSON objects (due to perl itself recursing deeply on croak +to free the temporary). If that is exceeded, the program crashes. to be +conservative, the default nesting limit is set to 512. If your process +has a smaller stack, you should adjust this setting accordingly with the +C method. And last but least, something else could bomb you that I forgot to think of. In that case, you get to keep the pieces. I am alway sopen for hints, @@ -642,6 +655,9 @@ =cut +sub true() { \1 } +sub false() { \0 } + 1; =head1 AUTHOR