http://qs1969.pair.com?node_id=11137217

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks

I have to extract some values from a JSON data. I have a sample here where I cant get to one of the values in one of the blocks. I would like to have this as a result:

Yes: Mary Lou - 11111 | 1 Yes: Mary Lou - 22222 | 2 Yes: John De - 33333 | 1 Yes: Smith Doe - 4444 | 1 No sec value, just the name: Joseph D.

But I can not get to the value:
Yes: Mary Lou - 11111 | 1

Instead, I am getting just this:
Yes: Mary Lou - 22222 | 2 Yes: John De - 33333 | 1 Yes: Smith Doe - 4444 | 1 No sec value, just the name: Joseph D.

Any help on that?
#!/usr/bin/perl use strict; use warnings; use JSON::XS; use JSON qw( ); use Data::Dumper; my $json = '{ "required": [ { "docs": [ { "sec": "11111", "number": "1" } ], "docs": [ { "sec": "22222", "number": "2" } ], "name": "Mary Lou" }, { "docs": [ { "sec": "33333", "number": "1" } ], "name": "John De" }, { "docs": [ { "sec": "4444", "number": "1" } ], "name": "Smith Doe" }, { "name": "Joseph D." } ] }'; my $json_data = JSON->new; my $data = $json_data->decode($json); for my $dta ( @{ $data->{ required } || [] } ){ if( scalar @{ $dta->{ docs } || [] } ){ for my $doc_data ( @{ $dta->{ docs } || [] } ){ if( $doc_data->{'sec'} ) { print "\n Yes: $dta->{'name'} - $doc_data->{'sec'} | $doc_da +ta->{'number'} \n"; } } }else { warn "\n No sec value, just the name: $dta->{'name'} \n\n"; } }

Thanks for looking!