… | |
… | |
673 | when there is trailing garbage after the first JSON object, it will |
673 | when there is trailing garbage after the first JSON object, it will |
674 | silently stop parsing there and return the number of characters consumed |
674 | silently stop parsing there and return the number of characters consumed |
675 | so far. |
675 | so far. |
676 | |
676 | |
677 | This is useful if your JSON texts are not delimited by an outer protocol |
677 | This is useful if your JSON texts are not delimited by an outer protocol |
678 | (which is not the brightest thing to do in the first place) and you need |
|
|
679 | to know where the JSON text ends. |
678 | and you need to know where the JSON text ends. |
680 | |
679 | |
681 | JSON::XS->new->decode_prefix ("[1] the tail") |
680 | JSON::XS->new->decode_prefix ("[1] the tail") |
682 | => ([], 3) |
681 | => ([], 3) |
683 | |
682 | |
684 | =back |
683 | =back |
… | |
… | |
778 | =back |
777 | =back |
779 | |
778 | |
780 | =head2 LIMITATIONS |
779 | =head2 LIMITATIONS |
781 | |
780 | |
782 | All options that affect decoding are supported, except |
781 | All options that affect decoding are supported, except |
783 | C<allow_nonref>. The reason for this is that it cannot be made to |
782 | C<allow_nonref>. The reason for this is that it cannot be made to work |
784 | work sensibly: JSON objects and arrays are self-delimited, i.e. you can concatenate |
783 | sensibly: JSON objects and arrays are self-delimited, i.e. you can |
785 | them back to back and still decode them perfectly. This does not hold true |
784 | concatenate them back to back and still decode them perfectly. This does |
786 | for JSON numbers, however. |
785 | not hold true for JSON numbers, however. |
787 | |
786 | |
788 | For example, is the string C<1> a single JSON number, or is it simply the |
787 | For example, is the string C<1> a single JSON number, or is it simply the |
789 | start of C<12>? Or is C<12> a single JSON number, or the concatenation |
788 | start of C<12>? Or is C<12> a single JSON number, or the concatenation |
790 | of C<1> and C<2>? In neither case you can tell, and this is why JSON::XS |
789 | of C<1> and C<2>? In neither case you can tell, and this is why JSON::XS |
791 | takes the conservative route and disallows this case. |
790 | takes the conservative route and disallows this case. |
… | |
… | |
1006 | |
1005 | |
1007 | =over 4 |
1006 | =over 4 |
1008 | |
1007 | |
1009 | =item hash references |
1008 | =item hash references |
1010 | |
1009 | |
1011 | Perl hash references become JSON objects. As there is no inherent ordering |
1010 | Perl hash references become JSON objects. As there is no inherent |
1012 | in hash keys (or JSON objects), they will usually be encoded in a |
1011 | ordering in hash keys (or JSON objects), they will usually be encoded |
1013 | pseudo-random order that can change between runs of the same program but |
1012 | in a pseudo-random order. JSON::XS can optionally sort the hash keys |
1014 | stays generally the same within a single run of a program. JSON::XS can |
1013 | (determined by the I<canonical> flag), so the same datastructure will |
1015 | optionally sort the hash keys (determined by the I<canonical> flag), so |
1014 | serialise to the same JSON text (given same settings and version of |
1016 | the same datastructure will serialise to the same JSON text (given same |
1015 | JSON::XS), but this incurs a runtime overhead and is only rarely useful, |
1017 | settings and version of JSON::XS), but this incurs a runtime overhead |
1016 | e.g. when you want to compare some JSON text against another for equality. |
1018 | and is only rarely useful, e.g. when you want to compare some JSON text |
|
|
1019 | against another for equality. |
|
|
1020 | |
1017 | |
1021 | =item array references |
1018 | =item array references |
1022 | |
1019 | |
1023 | Perl array references become JSON arrays. |
1020 | Perl array references become JSON arrays. |
1024 | |
1021 | |