In Perl, How can I print only the values extracted through json? -


i have json file contains content. opening json using extract_json. want access value of attribute "d"

sub extract_json{ $file = shift; local $/;     open $fh, "<", "$file";     $json = <$fh>; return $json; }  $targetfile = extract_json(' url of json file'); $object = json::xs->new->decode (decode "utf-8", $targetfile);  $flat_hash = { 'var'=> $object->{'a'}{'b'}{'c'}{'d'}  }; 

the content of variable d ['31', '45']. need value assigned "var" ['31', '45'].

please me in getting desired output.

try following

use warnings; use strict; use json::xs; $targetfile = extract_json('file.json'); $object = json::xs->new->utf8->decode($targetfile);  $flat_hash =  {     'var'=> $object->{'a'}{'b'}{'c'}{'d'} };   sub extract_json{     $file = shift;     local $/;     open $fh, "<", "$file";     $json = <$fh>;     return $json; }  foreach $key (keys %{$flat_hash}) #dereferencing hash ref {      foreach (@{$$flat_hash{$key}})  #iterating loop array ref     {         print "$key => $_\n";     }  } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -