Perhaps this may help

use strict; use warnings; my $data = { 'sections' => [ { 'images' => [], 'level' => 1, 'content' => [], 'title' => '10-minute Turkey' }, { 'images' => [], 'level' => 2, 'content' => [ { 'text' => 'Makes 4 servings.', 'type' => 'paragraph' } ], 'title' => 'Description' }, { 'images' => [], 'level' => 2, 'content' => [ { 'elements' => [ { 'elements' => [], 'text' => 'abc' }, { 'elements' => [], 'text' => 'efg' }, { 'elements' => [], 'text' => 'hij' }, ], 'type' => 'list' } ], 'title' => 'Ingredients' }, { 'images' => [], 'level' => 2, 'content' => [ { 'elements' => [ { 'elements' => [], 'text' => 'tuv' }, { 'elements' => [], 'text' => 'wxy' }, { 'elements' => [], 'text' => 'z12' }, ], 'type' => 'list' } ], 'title' => 'Directions' } ] }; deepdump($data,'$data->'); sub deepdump { my $data=shift; my $isname=shift; my $iam=ref $data; if ($iam eq 'HASH') { my @keys=keys(%$data); if (0==scalar(@keys)){print $isname.'={}'."\n";} else {for my $k (@keys) { deepdump($data->{$k},$isname.'{'.$k.'}'); +} } } # hash elsif ($iam eq 'ARRAY') { my $ict=0; if (0==scalar(@$data)){print $isname.'=[]'."\n";} else {for my $i (@$data) { deepdump($data->[$ict],$isname.'['.$ict.' +]'); $ict++} } } # array else {print $isname.'='.$data."\n";} } exit;
Result:
$data->{sections}[0]{content}=[] $data->{sections}[0]{title}=10-minute Turkey $data->{sections}[0]{images}=[] $data->{sections}[0]{level}=1 $data->{sections}[1]{level}=2 $data->{sections}[1]{title}=Description $data->{sections}[1]{images}=[] $data->{sections}[1]{content}[0]{text}=Makes 4 servings. $data->{sections}[1]{content}[0]{type}=paragraph $data->{sections}[2]{content}[0]{type}=list $data->{sections}[2]{content}[0]{elements}[0]{elements}=[] $data->{sections}[2]{content}[0]{elements}[0]{text}=abc $data->{sections}[2]{content}[0]{elements}[1]{elements}=[] $data->{sections}[2]{content}[0]{elements}[1]{text}=efg $data->{sections}[2]{content}[0]{elements}[2]{elements}=[] $data->{sections}[2]{content}[0]{elements}[2]{text}=hij $data->{sections}[2]{title}=Ingredients $data->{sections}[2]{images}=[] $data->{sections}[2]{level}=2 $data->{sections}[3]{images}=[] $data->{sections}[3]{title}=Directions $data->{sections}[3]{content}[0]{type}=list $data->{sections}[3]{content}[0]{elements}[0]{text}=tuv $data->{sections}[3]{content}[0]{elements}[0]{elements}=[] $data->{sections}[3]{content}[0]{elements}[1]{elements}=[] $data->{sections}[3]{content}[0]{elements}[1]{text}=wxy $data->{sections}[3]{content}[0]{elements}[2]{elements}=[] $data->{sections}[3]{content}[0]{elements}[2]{text}=z12 $data->{sections}[3]{level}=2


In reply to Re: Processing JSON with Perl by huck
in thread Processing JSON with Perl by DanielSpaniel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.