user476918 user476918 - 1 month ago 5
Perl Question

JSON string and PERL

How can I read a JSON string like this without "headers":

[{"SMS":"hello","NUM":12345},{"SMS":"bye","NUM":54321}]




my $json = JSON->new->utf8;
my $perl_data = $json->decode($content);
print ref($perl_data) . "\n";


returns ARRAY. I would like each element.

Thanks

Answer

There is an array ref around the hash references. You need to iterate over the array reference to get each element.

use Data::Dumper;

foreach my $elem (@{ $perl_data }) {
    print Dumper $elem;
}