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!