Perl Monk, Perl Meditation | |
PerlMonks |
Parsing JSON out of an incremental streamby Sec (Monk) |
on Feb 15, 2019 at 16:40 UTC ( [id://1229969]=perlquestion: print w/replies, xml ) | Need Help?? |
Sec has asked for the wisdom of the Perl Monks concerning the following question: Hi. I'm looking for a simple way to parse JSON objects out of a stream. I am calling an HTTP service that returns a stream of json objects over time. To read it, i registered a simple callback handler in LWP::UserAgent
As expected, i sometimes get partial json objects in $data. My first idea would be to so something like m/{.*?}/ against $data. Or rather some more elaborate version that deals with balanced parens and quoted strings. My question is, is there an easier / simpler / more straightforward way to deal with something like this that I am missing? -- SecEDIT: to clarify a bit. The problem is that in the callback $data may just be which means I have to grab one object, handle it, keep the rest and wait for more data. I know how to write code for that "the long way". I was asking if there is something clever or an existing module that can help with this.
Back to
Seekers of Perl Wisdom
|
|