title: Accessing values of json structure in perl
body: <p>I have a json structure that I'm decoding that looks like this:</p>
  
  <pre><code>  person =&gt; {
      city =&gt; "Chicago",
      id =&gt; 123,
      name =&gt; "Joe Smith",
      pets =&gt; {
        cats =&gt; [
                  { age =&gt; 6, name =&gt; "cat1", type =&gt; "siamese", weight =&gt; "10 kilos" },
                  { age =&gt; 10, name =&gt; "cat2", type =&gt; "siamese", weight =&gt; "13 kilos" },
                ],
        dogs =&gt; [
                  { age =&gt; 7, name =&gt; "dog1", type =&gt; "siamese", weight =&gt; "20 kilos" },
                  { age =&gt; 5, name =&gt; "dog2", type =&gt; "siamese", weight =&gt; "15 kilos" },
                ],
      },
    },
  }
  </code></pre>
  
  <p>I'm able to print the <code>city</code>, <code>id</code>, <code>name</code> by doing:</p>
  
  <pre><code>foreach my $listing ($decoded-&gt;{person})
  { 
      my $city = $listing-&gt;{city};
      my $name = $listing-&gt;{name};
      name - $city - \n";
  }
  </code></pre>
  
  <p>however, I'm unsure of how to print the <code>pets-&gt;cats</code> or <code>pets-&gt;dogs</code>. I'm able to do a dump of them by:</p>
  
  <pre><code>my @pets = $listing-&gt;{pets}-&gt;{cats};
  dump @pets;
  </code></pre>
  
  <p>but I'm not sure how to access them through the hash structure.</p>