in reply to Trying to decode JSON streaming from a website

I don't think that JSON::SL likes invalid JSON, and if your stream is coming in without the commas separating the JSON objects, it is not valid JSON.

You will have to find a way to insert the commas before feeding the data to JSON::SL. Maybe s/\{"sequenceNumber/,\{"sequenceNumber/g is already enough. If you are lucky, the JSON stream really has the newlines as you showed, then you can do s!\n!,!g.

Replies are listed 'Best First'.
Re^2: Trying to decode JSON streaming from a website
by ve6sar (Novice) on Apr 14, 2017 at 22:49 UTC
    I added commas to the end of each line, and now JSON::SL is trying to decode at least now I'm getting a hash ref error...
    JSON Stream parser test Received: {"sequenceNumber":1402012831,"frequency":7077409,"mode":"JT65","sNR":- +21,"flowStartSeconds":1492208570,"senderCallsign":"EB5JRL","senderLoc +ator":"IM99SL","receiverCallsign":"ON3HPI","receiverLocator":"JO20et" +,"receiverDecoderSoftware":"JTDX v17.7"}, Can't use string ("1402012831") as a HASH ref while "strict refs" in u +se at client.pl line 38.
    Should it not be using "sequenceNumber" as the reference and "1402012831" as the data? The line it fails on is  print "$obj->{Value}{flowStartSeconds}: $obj->{Value}{senderCallsign}\n"; If I use Data::Dumper the first element looks like below, could it be I've got my JSON pointer wrong so it's not looking at the whole line?
    $VAR1 = { 'Value' => 1402024539, 'Path' => '/sequenceNumber', 'JSONPointer' => '/^' };
    I'm not overly strong in OO Perl, I know I should how to use it more. Thanks

      I don't know JSON::SL, but it seems that you have to configure it better to call your code at different times than it currently does.

      I don't know what kind of JSON path spec it implements, but have you tried just using / instead of /^?

      If you post a short, self-contained program that still reproduces the error, then we can give help more to the point than just guess about your data, your code and the behaviour of JSON::SL. See also SSCCE.