How to read https JSON stream from perl?

Okay, I'll try as detailed as possible.

I need to connect to an https url that transmits JSON data and looks for keywords through REGEX as data streams, then take the corresponding JSON element, decode it, and insert it into the database.

REGEX on is not a problem, relatively simple.

What I am struggling with is reading the data line. I tried several examples I found on the internet for using LWP but where the thread never stops the script from loading.

Here is the closest I got

#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
use IO::String;

my $handle = IO::String->new(get("https://stackoverflow.com"));
while (defined (my $line = <$handle>)) {
  print $line; #Inserted for testing

  #Decode and insert into DB here       
}
close $handle;

      

The data is coming in pretty fast, so the script needs to be efficient.

Any guidance on how to do this would be great.

Thanks Sean

+3


source to share


1 answer


JSON :: SL can help you.



Also see Chas. Owens answer where it compares JSON :: SL and JSON :: Streaming :: Reader .

+1


source







All Articles