Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^5: JSON and Perl Objects - How to access data?

by AnomalousMonk (Bishop)
on Sep 06, 2015 at 13:04 UTC ( #1141194=note: print w/replies, xml ) Need Help??

in reply to Re^4: JSON and Perl Objects - How to access data?
in thread JSON and Perl Objects - How to access data?

See also the Data Structures Cookbook.

I'm going to have to wrap my head around ...

One way to go about that is to dump (see Data::Dumper; see also Data::Dump) the Perl object reference in stages, and from the inside out (i.e., top level to bottom):
    print Dumper $obj->{'items'};
will show that you have a reference to an array. Then
    print Dumper $obj->{'items'}->[1];
will show that one element of the array contains a hash reference. Finally,
    print Dumper ${ $obj->{'items'}->[1] }{'name'};
will show the value of one key of the referent.

Update: BTW: the expression
    ${ $obj->{'items'}->[1] }{'name'}
is equivalent to the more concise and IMHO preferable

Give a man a fish:  <%-{-{-{-<

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1141194]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2021-03-09 08:09 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (132 votes). Check out past polls.