I am trying parsing JSON from a website. I am having problem in parsing JSON. I am getting following error:
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "<html...") at D:\parser.pl line 45.
The URL is: https://coinmarketcap.com/coins
Any help would be appreciated. My code snippet is:
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Simple;
use HTML::TreeBuilder;
use JSON;
use IO::Socket::SSL;
use Data::Dumper;
sub getJSON {
my $url = $_[0] or die "URL missing!\n";
my $ua = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => SSL_VERIFY_NONE(),
verify_hostname => 0,
}
);
my $req = HTTP::Request->new( GET => $url );
$req->content_type('application/json');
my $res = $ua->request($req);
die $res->status_line unless $res->is_success;
my $json = JSON->new();
my $json_text = $json->decode( $res->content );
}
Content-Typeheader on a GET request does not make sense. This header describes the type of the content in the request body. But since this is a GET request there is no request body which also means that this none existing body has no type.