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.79 by root, Wed Dec 19 11:42:52 2007 UTC vs.
Revision 1.80 by root, Sat Dec 29 17:22:39 2007 UTC

905=back 905=back
906 906
907 907
908=head2 JSON and YAML 908=head2 JSON and YAML
909 909
910You often hear that JSON is a subset (or a close subset) of YAML. This is, 910You often hear that JSON is a subset of YAML. This is, however, a mass
911however, a mass hysteria and very far from the truth. In general, there is 911hysteria and very far from the truth. In general, there is no way to
912no way to configure JSON::XS to output a data structure as valid YAML. 912configure JSON::XS to output a data structure as valid YAML that works for
913all cases.
913 914
914If you really must use JSON::XS to generate YAML, you should use this 915If you really must use JSON::XS to generate YAML, you should use this
915algorithm (subject to change in future versions): 916algorithm (subject to change in future versions):
916 917
917 my $to_yaml = JSON::XS->new->utf8->space_after (1); 918 my $to_yaml = JSON::XS->new->utf8->space_after (1);
918 my $yaml = $to_yaml->encode ($ref) . "\n"; 919 my $yaml = $to_yaml->encode ($ref) . "\n";
919 920
920This will usually generate JSON texts that also parse as valid 921This will usually generate JSON texts that also parse as valid
921YAML. Please note that YAML has hardcoded limits on (simple) object key 922YAML. Please note that YAML has hardcoded limits on (simple) object key
922lengths that JSON doesn't have, so you should make sure that your hash 923lengths that JSON doesn't have and also has different and incompatible
924unicode handling, so you should make sure that your hash keys are
923keys are noticeably shorter than the 1024 characters YAML allows. 925noticeably shorter than the 1024 "stream characters" YAML allows and that
926you do not have codepoints with values outside the Unicode BMP (basic
927multilingual page).
924 928
925There might be other incompatibilities that I am not aware of. In general 929There might be other incompatibilities that I am not aware of. In general
926you should not try to generate YAML with a JSON generator or vice versa, 930you should not try to generate YAML with a JSON generator or vice versa,
927or try to parse JSON with a YAML parser or vice versa: chances are high 931or try to parse JSON with a YAML parser or vice versa: chances are high
928that you will run into severe interoperability problems. 932that you will run into severe interoperability problems when you least
933expect it.
929 934
930 935
931=head2 SPEED 936=head2 SPEED
932 937
933It seems that JSON::XS is surprisingly fast, as shown in the following 938It seems that JSON::XS is surprisingly fast, as shown in the following

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines