Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Parsing Array of arrays from json file

by 1nickt (Abbot)
on Sep 12, 2021 at 10:07 UTC ( #11136677=note: print w/replies, xml ) Need Help??


in reply to Parsing Array of arrays from json file

Hi,

Your program is well structured and you correctly are printing out the array to debug. But the dump shows that each record is itself an array of arrays, so you need one more level of dereferencing.

Change line 25 to

print "Translation for $record->[0][1] is $record->[0][ +0]\n";

Hope this helps!

edit: got the indices the wrong way around


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Parsing Array of arrays from json file
by Anonymous Monk on Sep 12, 2021 at 10:24 UTC

    Thank you. This is a good point. However, the script does not loop correctly through @records (only first element is printout)

      Since the structure is one level deeper than you thought, you need to add another loop. Try this:

      my @categories = $decoded_json[0]; foreach my $category (@categories){ foreach my $record (@$category) { print Dumper $record; print "Translation for $record->[0] is $record->[1 +]\n"; } }

      Hope this helps!


      The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-10-21 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (84 votes). Check out past polls.

    Notices?