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.152 by root, Wed Oct 30 22:11:01 2013 UTC vs.
Revision 1.156 by root, Sun Feb 21 15:37:53 2016 UTC

402character, after which more white-space and comments are allowed. 402character, after which more white-space and comments are allowed.
403 403
404 [ 404 [
405 1, # this comment not allowed in JSON 405 1, # this comment not allowed in JSON
406 # neither this one... 406 # neither this one...
407 ]
408
409=item * literal ASCII TAB characters in strings
410
411Literal ASCII TAB characters are now allowed in strings (and treated as
412C<\t>).
413
414 [
415 "Hello\tWorld",
416 "Hello<TAB>World", # literal <TAB> would not normally be allowed
407 ] 417 ]
408 418
409=back 419=back
410 420
411=item $json = $json->canonical ([$enable]) 421=item $json = $json->canonical ([$enable])
687 697
688This is useful if your JSON texts are not delimited by an outer protocol 698This is useful if your JSON texts are not delimited by an outer protocol
689and you need to know where the JSON text ends. 699and you need to know where the JSON text ends.
690 700
691 JSON::XS->new->decode_prefix ("[1] the tail") 701 JSON::XS->new->decode_prefix ("[1] the tail")
692 => ([], 3) 702 => ([1], 3)
693 703
694=back 704=back
695 705
696 706
697=head1 INCREMENTAL PARSING 707=head1 INCREMENTAL PARSING
1612 1622
1613And after decoding the JSON text, you could walk the data 1623And after decoding the JSON text, you could walk the data
1614structure looking for arrays with a first element of 1624structure looking for arrays with a first element of
1615C<XU1peReLzT4ggEllLanBYq4G9VzliwKF>. 1625C<XU1peReLzT4ggEllLanBYq4G9VzliwKF>.
1616 1626
1617The same approach cna be used to create the tagged format with another 1627The same approach can be used to create the tagged format with another
1618encoder. First, you create an array with the magic string as first member, 1628encoder. First, you create an array with the magic string as first member,
1619the classname as second, and constructor arguments last, encode it as part 1629the classname as second, and constructor arguments last, encode it as part
1620of your JSON structure, and then: 1630of your JSON structure, and then:
1621 1631
1622 $json =~ s/\[\s*"XU1peReLzT4ggEllLanBYq4G9VzliwKF"\s*,\s*("([^\\":,]+|\\.|::)*")\s*,/($1)[/g; 1632 $json =~ s/\[\s*"XU1peReLzT4ggEllLanBYq4G9VzliwKF"\s*,\s*("([^\\":,]+|\\.|::)*")\s*,/($1)[/g;
1623 1633
1624Again, this has some limitations - the magic string must not be encoded 1634Again, this has some limitations - the magic string must not be encoded
1625with character escapes, and the constructor arguments must be non-empty. 1635with character escapes, and the constructor arguments must be non-empty.
1636
1637
1638=head1 RFC7159
1639
1640Since this module was written, Google has written a new JSON RFC, RFC 7159
1641(and RFC7158). Unfortunately, this RFC breaks compatibility with both the
1642original JSON specification on www.json.org and RFC4627.
1643
1644As far as I can see, you can get partial compatibility when parsing by
1645using C<< ->allow_nonref >>. However, consider thew security implications
1646of doing so.
1647
1648I haven't decided yet when to break compatibility with RFC4627 by default
1649(and potentially leave applications insecure) and change the default to
1650follow RFC7159, but application authors are well advised to call C<<
1651->allow_nonref(0) >> even if this is the current default, if they cannot
1652handle non-reference values, in preparation for the day when the4 default
1653will change.
1654
1626 1655
1627=head1 THREADS 1656=head1 THREADS
1628 1657
1629This module is I<not> guaranteed to be thread safe and there are no 1658This module is I<not> guaranteed to be thread safe and there are no
1630plans to change this until Perl gets thread support (as opposed to the 1659plans to change this until Perl gets thread support (as opposed to the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines