Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Parsing JSON out of an incremental stream

by Sec (Monk)
on Feb 18, 2019 at 13:13 UTC ( [id://1230097]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing JSON out of an incremental stream
in thread Parsing JSON out of an incremental stream

I went and had look at that.

Unfortunately it looks like incr_parse is not capable of actually accepting random snippets.

>perl -MJSON -e 'my $json = JSON->new;$foo=$json->incr_parse(q!{"check +_result!);' unexpected end of string while parsing JSON string, at character offse +t 14 (before "(end of string)") at -e line 1.
This makes it unusable in my scenario.

Replies are listed 'Best First'.
Re^3: Parsing JSON out of an incremental stream
by haj (Vicar) on Feb 18, 2019 at 13:36 UTC

    I can reproduce this, but only with with JSON::PP. With JSON::XS, it works like a charm:

    PERL_JSON_BACKEND=JSON::PP perl -MData::Dump=dump -MJSON -E 'my $json = JSON->new;@foo=$json->incr_parse(q!{"check_result!); $bar=$json->incr_parse(q!" : "ok"}!); dump $bar'

    Output: unexpected end of string while parsing JSON string, at character offset 14 (before "(end of string)") at -e line 1.

    PERL_JSON_BACKEND=JSON::XS perl -MData::Dump=dump -MJSON -E 'my $json = JSON->new;@foo=$json->incr_parse(q!{"check_result!); $bar=$json->incr_parse(q!" : "ok"}!); dump $bar

    Output: { check_result => "ok" }

      I made an issue on github https://github.com/makamaka/JSON-PP/issues/45.

      I just realized, as JSON:PP is now part of core, that may have been the wrong place.

        JSON::PP has been core for quite a long time now, the issue you've raised is in the right place. I'm pretty sure Kenichi is correct, and that this is related to an old version of the module:

        marto@Shemp:~$ perl -MJSON::PP -e 'print $JSON::PP::VERSION' 2.97001marto@Shemp:~$ marto@Shemp:~$ PERL_JSON_BACKEND=JSON::PP perl -MData::Dump=dump -MJSO +N -E 'my $json = JSON->new;@foo=$json->incr_parse(q!{"check_result!); + $bar=$json->incr_parse(q!" : "ok"}!); dump $bar' { check_result => "ok" } ... after a cpanm JSON::PP marto@Shemp:~$ perl -MJSON::PP -e 'print $JSON::PP::VERSION' 4.00 marto@ShempPERL_JSON_BACKEND=JSON::PP perl -MData::Dump=dump -MJSON -E + 'my $json = JSON->new;@foo=$json->incr_parse(q!{"check_result!); $ba +r=$json->incr_parse(q!" : "ok"}!); dump $bar' { check_result => "ok" } marto@Shemp:~$ perl -v This is perl 5, version 26, subversion 1 (v5.26.1) built for i686-linu +x-gnu-thread-multi-64int

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found