title: Accessing nested JSON elements in Perl
body: <p>I get an error when attempting to access the contents of my JSON array.</p>
  
  <p>Here is the contents of my JSON array assets.json:</p>
  
  <pre><code>[{"id":1002,"interfaces":[{"ip_addresses":[{"value":"172.16.77.239"}]}]},{"id":1003,"interfaces":[{"ip_addresses":[{"value":"192.168.0.2"}]}]}]
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use JSON::XS;
  use File::Slurp;
  
  my $json_source = "assets.json";   
  
  my $json = read_file( $json_source ) ;
  my $json_array = decode_json $json;
  
  foreach my $item( @$json_array ) { 
      print $item-&gt;{id};
          print "\n";
      print $item-&gt;{interfaces}-&gt;{ip_addresses}-&gt;{value};
          print "\n\n";
  }
  </code></pre>
  
  <p>I get the expected output for $item->{id} but when accessing the nested element
  I get the error "Not a HASH reference"</p>