… | |
… | |
101 | |
101 | |
102 | =cut |
102 | =cut |
103 | |
103 | |
104 | package JSON::XS; |
104 | package JSON::XS; |
105 | |
105 | |
|
|
106 | no warnings; |
106 | use strict; |
107 | use strict; |
107 | |
108 | |
108 | our $VERSION = '2.21'; |
109 | our $VERSION = '2.2222'; |
109 | our @ISA = qw(Exporter); |
110 | our @ISA = qw(Exporter); |
110 | |
111 | |
111 | our @EXPORT = qw(encode_json decode_json to_json from_json); |
112 | our @EXPORT = qw(encode_json decode_json to_json from_json); |
112 | |
113 | |
113 | sub to_json($) { |
114 | sub to_json($) { |
… | |
… | |
706 | In some cases, there is the need for incremental parsing of JSON |
707 | In some cases, there is the need for incremental parsing of JSON |
707 | texts. While this module always has to keep both JSON text and resulting |
708 | texts. While this module always has to keep both JSON text and resulting |
708 | Perl data structure in memory at one time, it does allow you to parse a |
709 | Perl data structure in memory at one time, it does allow you to parse a |
709 | JSON stream incrementally. It does so by accumulating text until it has |
710 | JSON stream incrementally. It does so by accumulating text until it has |
710 | a full JSON object, which it then can decode. This process is similar to |
711 | a full JSON object, which it then can decode. This process is similar to |
711 | using C<decode_prefix> to see if a full JSON object is available, but is |
712 | using C<decode_prefix> to see if a full JSON object is available, but |
712 | much more efficient (JSON::XS will only attempt to parse the JSON text |
713 | is much more efficient (and can be implemented with a minimum of method |
|
|
714 | calls). |
|
|
715 | |
|
|
716 | JSON::XS will only attempt to parse the JSON text once it is sure it |
713 | once it is sure it has enough text to get a decisive result, using a very |
717 | has enough text to get a decisive result, using a very simple but |
714 | simple but truly incremental parser). |
718 | truly incremental parser. This means that it sometimes won't stop as |
|
|
719 | early as the full parser, for example, it doesn't detect parenthese |
|
|
720 | mismatches. The only thing it guarantees is that it starts decoding as |
|
|
721 | soon as a syntactically valid JSON text has been seen. This means you need |
|
|
722 | to set resource limits (e.g. C<max_size>) to ensure the parser will stop |
|
|
723 | parsing in the presence if syntax errors. |
715 | |
724 | |
716 | The following two methods deal with this. |
725 | The following methods implement this incremental parser. |
717 | |
726 | |
718 | =over 4 |
727 | =over 4 |
719 | |
728 | |
720 | =item [void, scalar or list context] = $json->incr_parse ([$string]) |
729 | =item [void, scalar or list context] = $json->incr_parse ([$string]) |
721 | |
730 | |