#!/usr/bin/perl use strict; use IO::Socket::SSL; #qw(debug3); use JSON::SL; 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=IAMAFAKETOKEN HTTP/1.0\r\n\r\n"; print <$cl>; local $/ = \5; #read only 5 bytes at a time while (my $line = <$cl>) { $p->feed($line); #parse what you can fetch anything that completed the parse and matches the JSON Pointer while (my $obj = $p->fetch) { print "$obj->{Value}{sequenceNumber}: $obj->{Value}{senderCallsign}\n"; #Inserted for testing #do filtering and database stuff here } } close $cl;