简体   繁体   中英

JSON Array as List of Hash in Perl

I'm very new to Perl, I have a non symmetric JSON array like below:

[
{"KEY1":"14507226013384557","KEY2":"1234","KEY3":"7899"},
{"KEY1":"14507226013384557","KEY2":"1234","KEY3":"7899","KEY4":"TEST","KEY5":"TEST1"},
{"KEY1":"14507226013384557","KEY2":"1234","KEY3":"7899","KEY5":"TEST New"},
]

I want to parse and store JSON array in a list of HASH, and then iterate that list of hash and check value of each KEYs and the process it. Any Idea how can I do ? I have used JSON decode and printed using dumper but I am facing issue while iterating through it.

my $data = decode_json($json_utf8);

for my $row (@$data) {
    for my $key (keys(%$row)) {
       say "$key: $row->{$key}";
    }

    say "";
}

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM