#!/usr/bin/perl -CSDA use utf8; use Modern::Perl qw{2019}; use JSON; use Data::Dumper; sub extract_paths_values { my ($cur_node, $top_path, $put_here) = @_; $top_path //= "\$"; $put_here //= {}; if (ref $cur_node eq "HASH") { extract_paths_values($$cur_node{$_}, "$top_path\['$_'\]", $put_here) for keys %$cur_node; } elsif (ref $cur_node eq "ARRAY") { extract_paths_values($$cur_node[$_], "$top_path\[$_\]", $put_here) for 0 .. @$cur_node - 1; } else { $$put_here{$top_path} = $cur_node; } return $put_here; } my $json = ' { "store" : { "files": [ ["alfa.txt", "about first letter in greek"], ["model.dxf", "for architects"], ["errors.txt", "no need for that normally"], ], "book" : [ { "category" : "reference", "title" : "Sayings of the Century", "author" : "Nigel Rees", "price" : 8.95 }, { "author" : "Evelyn Waugh", "title" : "Sword of Honour", "price" : 12.99, "category" : "fiction" }, ], "bicycle" : [ { "price" : 19.95, "color" : "red" } ] }, "status" : { "curr" : "Okey", "code" : 232, } } '; my $paths_values = extract_paths_values( JSON->new->relaxed->decode($json) ); print "$_ ~~~~> $$paths_values{$_}\n" for sort keys %$paths_values; print "Hurray! Done that \n";