Browse files

updated 'INCREMENTAL PARSING' section

  • Loading branch information...
1 parent 9bb15fa commit 93c14366b97f8df2373ea39193d1eb0b305ed7bd @makamaka makamaka committed Apr 1, 2010
Showing with 23 additions and 9 deletions.
  1. +23 −9 lib/
@@ -7,7 +7,7 @@ use base qw(Exporter);
@JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);
- $JSON::VERSION = '2.19';
+ $JSON::VERSION = '2.19_01';
$JSON::DEBUG = 0 unless (defined $JSON::DEBUG);
@@ -608,7 +608,7 @@ JSON - JSON (JavaScript Object Notation) encoder/decoder
=head1 VERSION
- 2.19
+ 2.20
This version is compatible with JSON::XS B<2.27> and later.
@@ -1428,9 +1428,13 @@ With no argumnt, it returns all the above properties as a hash reference.
In JSON::XS 2.2, incremental parsing feature of JSON texts was implemented.
-=over 4
+=head2 incr_parse
-=item [void, scalar or list context] = $json->incr_parse ([$string])
+ $json->incr_parse( [$string] ) # void context
+ $obj_or_undef = $json->incr_parse( [$string] ) # scalar context
+ @obj_or_empty = $json->incr_parse( [$string] ) # list context
This is the central parsing function. It can both append new text and
extract objects from the stream accumulated so far (both of these
@@ -1458,7 +1462,13 @@ an error occurs, an exception will be raised as in the scalar context
case. Note that in this case, any previously-parsed JSON texts will be
-=item $lvalue_string = $json->incr_text
+Example: Parse some JSON arrays/objects in a given string and return them.
+ my @objs = JSON->new->incr_parse ("[5][7][1,2]");
+=head2 incr_text
+ $lvalue_string = $json->incr_text
This method returns the currently stored JSON fragment as an lvalue, that
is, you can manipulate it. This I<only> works when a preceding call to
@@ -1472,21 +1482,27 @@ This function is useful in two cases: a) finding the trailing text after a
JSON object or b) parsing multiple JSON objects separated by non-JSON text
(such as commas).
+ $json->incr_text =~ s/\s*,\s*//;
In Perl 5.005, C<lvalue> attribute is not available.
You must write codes like the below:
$string = $json->incr_text;
$string =~ s/\s*,\s*//;
$json->incr_text( $string );
-=item $json->incr_skip
+=head2 incr_skip
+ $json->incr_skip
This will reset the state of the incremental parser and will remove the
parsed text from the input buffer. This is useful after C<incr_parse>
died, in which case the input buffer and incremental parser state is left
unchanged, to skip the text parsed so far and to reset the parse state.
-=item $json->incr_reset
+=head2 incr_reset
+ $json->incr_reset
This completely resets the incremental parser, that is, after this call,
it will be as if the parser had never parsed anything.
@@ -1495,8 +1511,6 @@ This is useful if you want ot repeatedly parse JSON objects and want to
ignore any trailing data, which means you have to reset the parser after
each successful decode.
The below methods are JSON::PP own methods, so when C<JSON> works

0 comments on commit 93c1436

Please sign in to comment.