use warnings; use strict; use JSON; use Data::Dumper; use Ref::Util qw(is_arrayref is_hashref); my $companyNumber = 'NF001553'; my $request = "https://api.company-information.service.gov.uk/company/".$companyNumber."/officers"; my $curl = `curl -s --user youwillneedtoreplacethiswithyourapikey:"" $request` || die "Problem with CURL call\n"; my $decodedJSON = decode_json($curl) or die "this is not JSON\n"; if (is_hashref($decodedJSON)) { if (exists $decodedJSON->{items}) { for my $item (@{ $decodedJSON->{items} }) { if (exists $item->{name}) { print $item->{name}."\n"; } if (exists $item->{address}){ if (is_hashref($item->{address})){ if (exists $item->{address}->{address_line_1}){ print $item->{address}->{address_line_1}."\n";} if (exists $item->{address}->{address_line_2}){ print $item->{address}->{address_line_2}."\n";} if (exists $item->{address}->{locality}){ print $item->{address}->{locality}."\n";} if (exists $item->{address}->{region}){ print $item->{address}->{region}."\n";} if (exists $item->{address}->{postal_code}){ print $item->{address}->{postal_code}."\n";} } } } } }