… | |
… | |
103 | |
103 | |
104 | package JSON::XS; |
104 | package JSON::XS; |
105 | |
105 | |
106 | use strict; |
106 | use strict; |
107 | |
107 | |
108 | our $VERSION = '2.2'; |
108 | our $VERSION = '2.222'; |
109 | our @ISA = qw(Exporter); |
109 | our @ISA = qw(Exporter); |
110 | |
110 | |
111 | our @EXPORT = qw(encode_json decode_json to_json from_json); |
111 | our @EXPORT = qw(encode_json decode_json to_json from_json); |
112 | |
112 | |
113 | sub to_json($) { |
113 | sub to_json($) { |
… | |
… | |
706 | In some cases, there is the need for incremental parsing of JSON |
706 | 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 |
707 | 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 |
708 | 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 |
709 | 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 |
710 | 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 |
711 | 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 |
712 | is much more efficient (and can be implemented with a minimum of method |
|
|
713 | calls). |
|
|
714 | |
|
|
715 | 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 |
716 | has enough text to get a decisive result, using a very simple but |
714 | simple but truly incremental parser). |
717 | truly incremental parser. This means that it sometimes won't stop as |
|
|
718 | early as the full parser, for example, it doesn't detect parenthese |
|
|
719 | mismatches. The only thing it guarantees is that it starts decoding as |
|
|
720 | soon as a syntactically valid JSON text has been seen. This means you need |
|
|
721 | to set resource limits (e.g. C<max_size>) to ensure the parser will stop |
|
|
722 | parsing in the presence if syntax errors. |
715 | |
723 | |
716 | The following two methods deal with this. |
724 | The following methods implement this incremental parser. |
717 | |
725 | |
718 | =over 4 |
726 | =over 4 |
719 | |
727 | |
720 | =item [void, scalar or list context] = $json->incr_parse ([$string]) |
728 | =item [void, scalar or list context] = $json->incr_parse ([$string]) |
721 | |
729 | |