apparentlymart / libjson-streaming-reader-perl

Parse JSON strings in a streaming fashion
2 stars 3 forks source link

Support multiple-document streams #4

Open nichtich opened 11 years ago

nichtich commented 11 years ago

One should be able to read multiple JSON documents appended to each other. This could be enabled by an option.

use strict;
use Test::More;
use JSON::Streaming::Reader;

my $jsonr = JSON::Streaming::Reader->for_string(<<JSON);
    { "foo": 1 }
    { "bar": 2 }
JSON

my $got = [];
while (my $token = $jsonr->get_token()) { 
    push @$got, $token;
}

is_deeply $got, [ 
    [ 'start_object' ],
    [ 'start_property' => 'foo' ],
    [ 'add_number' => 1 ],
    [ 'end_property' ],
    [ 'end_object' ],
    [ 'start_object' ],
    [ 'start_property' => 'bar' ],
    [ 'add_number' => 2 ],
    [ 'end_property' ],
    [ 'end_object' ] 
];

note explain $got;

done_testing;
apparentlymart commented 11 years ago

Hi Jacob,

Thanks for the suggestion. That does sound useful, but unfortunately I'm not actively working on this module anymore since I rarely write Perl these days.

I'm happy to pass on maintainership to someone else if they have motivation to develop this module further.

nichtich commented 11 years ago

Ok, thanks for the response. I tell you if I might adopt the module after I will have been working on it in the next two month or so.