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.40 by root, Mon Jun 11 03:42:57 2007 UTC vs.
Revision 1.42 by root, Thu Jun 14 23:58:57 2007 UTC

614 614
615You often hear that JSON is a subset (or a close subset) of YAML. This is, 615You often hear that JSON is a subset (or a close subset) of YAML. This is,
616however, a mass hysteria and very far from the truth. In general, there is 616however, a mass hysteria and very far from the truth. In general, there is
617no way to configure JSON::XS to output a data structure as valid YAML. 617no way to configure JSON::XS to output a data structure as valid YAML.
618 618
619If you really must use JSON::XS to generate YAML, you should this 619If you really must use JSON::XS to generate YAML, you should use this
620algorithm (subject to change in future versions): 620algorithm (subject to change in future versions):
621 621
622 my $to_yaml = JSON::XS->new->utf8->space_after (1); 622 my $to_yaml = JSON::XS->new->utf8->space_after (1);
623 my $yaml = $to_yaml->encode ($ref) . "\n"; 623 my $yaml = $to_yaml->encode ($ref) . "\n";
624 624
625This will usually generate JSON texts that also parse as valid 625This will usually generate JSON texts that also parse as valid
626YAML. Please note that YAML has hardcoded limits on object key lengths 626YAML. Please note that YAML has hardcoded limits on (simple) object key
627that JSON doesn't have, so you should make sure that your hash keys are 627lengths that JSON doesn't have, so you should make sure that your hash
628noticably shorter than 1024 characters. 628keys are noticably shorter than the 1024 characters YAML allows.
629 629
630There might be other incompatibilities that I am not aware of. In general 630There might be other incompatibilities that I am not aware of. In general
631you should not try to generate YAML with a JSON generator or vice versa, 631you should not try to generate YAML with a JSON generator or vice versa,
632or try to parse JSON with a YAML parser or vice versa. 632or try to parse JSON with a YAML parser or vice versa: chances are high
633that you will run into severe interoperability problems.
633 634
634 635
635=head2 SPEED 636=head2 SPEED
636 637
637It seems that JSON::XS is surprisingly fast, as shown in the following 638It seems that JSON::XS is surprisingly fast, as shown in the following
719 720
720And last but least, something else could bomb you that I forgot to think 721And last but least, something else could bomb you that I forgot to think
721of. In that case, you get to keep the pieces. I am always open for hints, 722of. In that case, you get to keep the pieces. I am always open for hints,
722though... 723though...
723 724
725If you are using JSON::XS to return packets to consumption
726by javascript scripts in a browser you should have a look at
727L<http://jpsykes.com/47/practical-csrf-and-json-security> to see wether
728you are vulnerable to some common attack vectors (which really are browser
729design bugs, but it is still you who will have to deal with it, as major
730browser developers care only for features, not about doing security
731right).
732
724 733
725=head1 BUGS 734=head1 BUGS
726 735
727While the goal of this module is to be correct, that unfortunately does 736While the goal of this module is to be correct, that unfortunately does
728not mean its bug-free, only that I think its design is bug-free. It is 737not mean its bug-free, only that I think its design is bug-free. It is

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines