in reply to Re: Obtain the full path of a json key
in thread Obtain the full path of a json key

Thank you all for the contributions, I'm installing the missing package Path::Tiny to try all them :)
  • Comment on Re^2: Obtain the full path of a json key

Replies are listed 'Best First'.
Re^3: Obtain the full path of a json key
by tybalt89 (Monsignor) on Jun 23, 2025 at 19:41 UTC

    You don't really need Path::Tiny. If I didn't have it, I would have done something like this using just standard perl:

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11165436 use warnings; use JSON::PP; sub names { my ($data) = @_; if( 'ARRAY' eq ref $data ) { map names($_), @$data; } elsif( 'HASH' eq ref $data ) { map { my $id = $_; map "$id.$_", names($data->{$_}) } keys %$data; } else { "\n" } } @ARGV or @ARGV = 'd.11165436.json'; # FIXME filename print map s/\.$//r, names decode_json join '', <>;

    This would allow you to put the JSON file name on the command line, or if you didn't put any arguments on the command line, would run the program against a test file.