I have no cobbled together my own solution. It's less ugly than I expected.
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;
} );