ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.pm
(Generate patch)

Comparing JSON-XS/XS.pm (file contents):
Revision 1.52 by root, Mon Jul 2 02:57:11 2007 UTC vs.
Revision 1.59 by root, Mon Aug 27 01:49:01 2007 UTC

81 81
82package JSON::XS; 82package JSON::XS;
83 83
84use strict; 84use strict;
85 85
86our $VERSION = '1.4'; 86our $VERSION = '1.5';
87our @ISA = qw(Exporter); 87our @ISA = qw(Exporter);
88 88
89our @EXPORT = qw(to_json from_json); 89our @EXPORT = qw(to_json from_json);
90 90
91use Exporter; 91use Exporter;
277This setting has no effect when decoding JSON texts. 277This setting has no effect when decoding JSON texts.
278 278
279Example, space_before and indent disabled, space_after enabled: 279Example, space_before and indent disabled, space_after enabled:
280 280
281 {"key": "value"} 281 {"key": "value"}
282
283=item $json = $json->relaxed ([$enable])
284
285If C<$enable> is true (or missing), then C<decode> will accept some
286extensions to normal JSON syntax (see below). C<encode> will not be
287affected in anyway. I<Be aware that this option makes you accept invalid
288JSON texts as if they were valid!>. I suggest only to use this option to
289parse application-specific files written by humans (configuration files,
290resource files etc.)
291
292If C<$enable> is false (the default), then C<decode> will only accept
293valid JSON texts.
294
295Currently accepted extensions are:
296
297=over 4
298
299=item * list items can have an end-comma
300
301JSON I<separates> array elements and key-value pairs with commas. This
302can be annoying if you write JSON texts manually and want to be able to
303quickly append elements, so this extension accepts comma at the end of
304such items not just between them:
305
306 [
307 1,
308 2, <- this comma not normally allowed
309 ]
310 {
311 "k1": "v1",
312 "k2": "v2", <- this comma not normally allowed
313 }
314
315=back
282 316
283=item $json = $json->canonical ([$enable]) 317=item $json = $json->canonical ([$enable])
284 318
285If C<$enable> is true (or missing), then the C<encode> method will output JSON objects 319If C<$enable> is true (or missing), then the C<encode> method will output JSON objects
286by sorting their keys. This is adding a comparatively high overhead. 320by sorting their keys. This is adding a comparatively high overhead.
553are represented by the same codepoints in the Perl string, so no manual 587are represented by the same codepoints in the Perl string, so no manual
554decoding is necessary. 588decoding is necessary.
555 589
556=item number 590=item number
557 591
558A JSON number becomes either an integer or numeric (floating point) 592A JSON number becomes either an integer, numeric (floating point) or
559scalar in perl, depending on its range and any fractional parts. On the 593string scalar in perl, depending on its range and any fractional parts. On
560Perl level, there is no difference between those as Perl handles all the 594the Perl level, there is no difference between those as Perl handles all
561conversion details, but an integer may take slightly less memory and might 595the conversion details, but an integer may take slightly less memory and
562represent more values exactly than (floating point) numbers. 596might represent more values exactly than (floating point) numbers.
597
598If the number consists of digits only, JSON::XS will try to represent
599it as an integer value. If that fails, it will try to represent it as
600a numeric (floating point) value if that is possible without loss of
601precision. Otherwise it will preserve the number as a string value.
602
603Numbers containing a fractional or exponential part will always be
604represented as numeric (floating point) values, possibly at a loss of
605precision.
606
607This might create round-tripping problems as numbers might become strings,
608but as Perl is typeless there is no other way to do it.
563 609
564=item true, false 610=item true, false
565 611
566These JSON atoms become C<JSON::XS::true> and C<JSON::XS::false>, 612These JSON atoms become C<JSON::XS::true> and C<JSON::XS::false>,
567respectively. They are overloaded to act almost exactly like the numbers 613respectively. They are overloaded to act almost exactly like the numbers
878still relatively early in its development. If you keep reporting bugs they 924still relatively early in its development. If you keep reporting bugs they
879will be fixed swiftly, though. 925will be fixed swiftly, though.
880 926
881=cut 927=cut
882 928
883our $true = do { bless \(my $dummy = "1"), "JSON::XS::Boolean" }; 929our $true = do { bless \(my $dummy = 1), "JSON::XS::Boolean" };
884our $false = do { bless \(my $dummy = "0"), "JSON::XS::Boolean" }; 930our $false = do { bless \(my $dummy = 0), "JSON::XS::Boolean" };
885 931
886sub true() { $true } 932sub true() { $true }
887sub false() { $false } 933sub false() { $false }
888 934
889sub is_bool($) { 935sub is_bool($) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines