Skip to content

malformed JSON string #2

@seannherdy

Description

@seannherdy

When I attempt to pull a quote on symbol GSUM or BRK.A, my script throws this error and stops executing the main program:

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/local/share/perl5/5.32/Finance/QuoteHist/Yahoo.pm line 227.

Here's the code in question:

sub {
my $data = shift;
$data = decode_json($data);
my $data_result = $data->{chart}{result}[0] || {};
if ($target_mode eq "quote") {
return $json_quote_parse->($data_result);
}
elsif ($target_mode eq "split") {
return $json_split_parse->($data_result);
}
elsif ($target_mode eq "dividend") {
return $json_div_parse->($data_result);
}
else { die "unknown mode: $target_mode" }
};

The $data scalar is "" when this decode_json($data) is called on line 227. Would it be possible for Finance::QuoteHist::Yahoo to check for this and not attempt to parse empty JSON strings causing main script to exit?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions