#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use LWP::Simple; use JSON; ### using api from http://mymovieapi.com/ # define url for get request # ghostbusters url my $url = "http://mymovieapi.com/?id=tt0087332&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple&business=0&tech=0"; # receive JSON into $response, via get call using LWP::Simple my $response = get $url; # die if we have problems making the GET request die 'Error making GET request -> $url' unless defined $response; # usual print line for troubleshooting #print Dumper($response); ### using JSON's decode_json we decode the JSON string into an array @data # my array @data gets the decoded JSON string my @data = decode_json($response); #print Dumper($data); # for each element in the now decoded array, make them accessible foreach (@data) { print $_->{title} . " was released in year -> " . $_->{year} . " , and it is rated " . $_->{rating}; }