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.41 by root, Mon Jun 11 03:45:26 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines