… | |
… | |
629 | While this module always has to keep both JSON text and resulting Perl |
629 | While this module always has to keep both JSON text and resulting Perl |
630 | data structure in memory at one time, it does allow you to parse a JSON |
630 | data structure in memory at one time, it does allow you to parse a JSON |
631 | stream incrementally. It does so by accumulating text until it has a |
631 | stream incrementally. It does so by accumulating text until it has a |
632 | full JSON object, which it then can decode. This process is similar to |
632 | full JSON object, which it then can decode. This process is similar to |
633 | using "decode_prefix" to see if a full JSON object is available, but is |
633 | using "decode_prefix" to see if a full JSON object is available, but is |
634 | much more efficient (JSON::XS will only attempt to parse the JSON text |
634 | much more efficient (and can be implemented with a minimum of method |
635 | once it is sure it has enough text to get a decisive result, using a |
635 | calls). |
636 | very simple but truly incremental parser). |
|
|
637 | |
636 | |
638 | The following two methods deal with this. |
637 | JSON::XS will only attempt to parse the JSON text once it is sure it has |
|
|
638 | enough text to get a decisive result, using a very simple but truly |
|
|
639 | incremental parser. This means that it sometimes won't stop as early as |
|
|
640 | the full parser, for example, it doesn't detect parenthese mismatches. |
|
|
641 | The only thing it guarantees is that it starts decoding as soon as a |
|
|
642 | syntactically valid JSON text has been seen. This means you need to set |
|
|
643 | resource limits (e.g. "max_size") to ensure the parser will stop parsing |
|
|
644 | in the presence if syntax errors. |
|
|
645 | |
|
|
646 | The following methods implement this incremental parser. |
639 | |
647 | |
640 | [void, scalar or list context] = $json->incr_parse ([$string]) |
648 | [void, scalar or list context] = $json->incr_parse ([$string]) |
641 | This is the central parsing function. It can both append new text |
649 | This is the central parsing function. It can both append new text |
642 | and extract objects from the stream accumulated so far (both of |
650 | and extract objects from the stream accumulated so far (both of |
643 | these functions are optional). |
651 | these functions are optional). |