Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Parsing JSON out of an incremental stream

by huck (Parson)
on Feb 15, 2019 at 17:40 UTC ( #1229972=note: print w/replies, xml ) Need Help??


in reply to Parsing JSON out of an incremental stream

Although i havent used it, i remembered seeing something like this so i went looking for it again. JSON INCREMENTAL-PARSING. It seems to do what you want.

  • Comment on Re: Parsing JSON out of an incremental stream

Replies are listed 'Best First'.
Re^2: Parsing JSON out of an incremental stream
by Sec (Monk) on Feb 18, 2019 at 13:13 UTC
    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.

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2019-10-17 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?