Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Processing JSON with Perl

by Anonymous Monk
on Feb 17, 2017 at 20:58 UTC ( [id://1182241]=note: print w/replies, xml ) Need Help??


in reply to Processing JSON with Perl

See perldsc, note how $sec->{content} is not a hash reference but an array reference, and don't use $_ so much.
for my $sec ( @{ $data->{sections} } ) { print "Section: ", $sec->{title}, "\n"; for my $img ( @{ $sec->{images} } ) { print "Image: ", $img, "\n"; } print "Content Text: ", $sec->{content}[0]{text}//'(undef)' ,"\n"; for my $elem ( @{ $sec->{content}[0]{elements} } ) { print "Element Text: ", $elem->{text}, "\n"; } }
Output:
Section: 10-minute Turkey Content Text: (undef) Section: Description Content Text: Makes 4 servings. Section: Ingredients Content Text: (undef) Element Text: abc Element Text: efg Element Text: hij Section: Directions Content Text: (undef) Element Text: tuv Element Text: wxy Element Text: z12

Replies are listed 'Best First'.
Re^2: Processing JSON with Perl
by DanielSpaniel (Scribe) on Feb 20, 2017 at 11:04 UTC
    Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2026-04-11 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.