#!/usr/bin/perl use strict; use IO::Socket::SSL; #qw(debug3); use JSON::SL; use Data::Dumper; print "JSON Stream parser test\r\n"; my $p = JSON::SL->new; #Look for everything past the first JSON pointer $p->set_jsonpointer(["/^"]); # simple client my $cl = IO::Socket::SSL->new( PeerAddr => 'example.com', PeerService => 'https', PeerPort => 443, Proto => 'tcp', Reuse => 1 ); die "no connection" unless $cl -> connected(); print $cl "GET /stream/report?token=IMNOTAREALTOKEN HTTP/1.0\r\n\r\n"; #print <$cl>; #local $/ = \5; #read only 5 bytes at a time while (my $line = <$cl>) { chomp($line); #Remove new line characters $line = "[$line],\n"; # Add leading [ and trailing ], so it will parse correctly if ($line =~ m/{"\w{14}/) { print "Received:\n$line"; $p->feed($line); #parse what you can fetch anything that completed the parse and matches the JSON Pointer while (my $obj = $p->fetch) { print Dumper($obj); print "$obj->{Value}{flowStartSeconds}: $obj->{Value}{senderCallsign}\n"; } } } close $cl;