ve6sar has asked for the wisdom of the Perl Monks concerning the following question:
Using this code to test strictly the decode it works.#!/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 comple +ted the parse and matches the JSON Pointer while (my $obj = $p->fetch) { print "$obj->{Value}{sequenceNumber}: $obj->{Value}{sender +Callsign}\n"; #Inserted for testing #do filtering and database stuff here } } close $cl;
Here's a sample of the data as received, in the working decode script I had to add a comma at the end of each line.#!/usr/bin/perl use strict; use warnings; use JSON::SL; my $p = JSON::SL->new; #look for everthing past the first level (i.e. everything in the array +) $p->set_jsonpointer(["/^"]); local $/ = \5; #read only 5 bytes at a time while (my $buf = <DATA>) { $p->feed($buf); #parse what you can #fetch anything that completed the parse and matches the JSON Poin +ter while (my $obj = $p->fetch) { print "$obj->{Value}{sequenceNumber}: $obj->{Value}{senderCall +sign}\n"; } } __DATA__ [ {"sequenceNumber":1401615035,"frequency":7076402,"mode":"JT65","sNR +":-1,"flowStartSeconds":1492192912,"senderCallsign":"DJ0FX","senderLo +cator":"JN67KT","receiverCallsign":"OZ7IO","receiverLocator":"JO65gq" +,"receiverDecoderSoftware":"WSJT-X v1.7.0 r7405"}, {"sequenceNumber":1401615039,"frequency":7077903,"mode":"JT65","sN +R":-11,"flowStartSeconds":1492192973,"senderCallsign":"R7NO","senderL +ocator":"KN98","receiverCallsign":"OZ7IO","receiverLocator":"JO65gq", +"receiverDecoderSoftware":"WSJT-X v1.7.0 r7405"}, {"sequenceNumber":1401615040,"frequency":7076811,"mode":"JT65","sN +R":-11,"flowStartSeconds":1492193032,"senderCallsign":"F6AVP","sender +Locator":"JN28UX","receiverCallsign":"OZ7IO","receiverLocator":"JO65g +q","receiverDecoderSoftware":"WSJT-X v1.7.0 r7405"} ]
{"sequenceNumber":1401615035,"frequency":7076402,"mode":"JT65","sNR":- +1,"flowStartSeconds":1492192912,"senderCallsign":"DJ0FX","senderLocat +or":"JN67KT","receiverCallsign":"OZ7IO","receiverLocator":"JO65gq","r +eceiverDecoderSoftware":"WSJT-X v1.7.0 r7405"} {"sequenceNumber":1401615036,"frequency":7076996,"mode":"JT65","sNR":- +6,"flowStartSeconds":1492192912,"senderCallsign":"RU6MO","senderLocat +or":"KN97KF","receiverCallsign":"OZ7IO","receiverLocator":"JO65gq","r +eceiverDecoderSoftware":"WSJT-X v1.7.0 r7405"} {"sequenceNumber":1401615037,"frequency":7077360,"mode":"JT65","sNR":- +5,"flowStartSeconds":1492192913,"senderCallsign":"RV3QD","senderLocat +or":"KO91NQ","receiverCallsign":"OZ7IO","receiverLocator":"JO65gq","r +eceiverDecoderSoftware":"WSJT-X v1.7.0 r7405"}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to decode JSON streaming from a website
by Corion (Patriarch) on Apr 14, 2017 at 21:31 UTC | |
by ve6sar (Novice) on Apr 14, 2017 at 22:49 UTC | |
by Corion (Patriarch) on Apr 15, 2017 at 07:35 UTC | |
|
Re: Trying to decode JSON streaming from a website
by huck (Prior) on Apr 14, 2017 at 21:41 UTC | |
|
Re: Trying to decode JSON streaming from a website
by Anonymous Monk on Apr 14, 2017 at 21:29 UTC | |
by ve6sar (Novice) on Apr 14, 2017 at 22:29 UTC | |
by ve6sar (Novice) on Apr 14, 2017 at 23:53 UTC |