Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Obtain the full path of a json key

by Anonymous Monk
on Jun 23, 2025 at 13:40 UTC ( [id://11165449]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11165449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2025-12-17 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (98 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.