in reply to Parsing JSON out of an incremental stream
Most tricky part (for me) was to come up with a regexp that works well enough for me. (I don't correctly deal with hashes inside arrays)
our $store; $ua->add_handler( response_data => sub { my($response, $ua, $h, $data) = @_; $store.=$data; eval { if ($store =~ s/^\s*({\s*(?:"[^"]*"|(?>[^"{}]* +)|(?1))+\s*})\s*//){ my $result = $json->decode( $1 ); print Dumper $result; }; }; if ($@){ print STDERR "Error: $@\n"; die }; 1; } );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parsing JSON out of an incremental stream
by Your Mother (Archbishop) on Feb 15, 2019 at 18:53 UTC | |
Re^2: Parsing JSON out of an incremental stream
by Sec (Monk) on Feb 18, 2019 at 17:40 UTC |