Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by tybalt89 (Monsignor)
on Jun 23, 2025 at 19:41 UTC ( [id://11165451]=note: print w/replies, xml ) Need Help??


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

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://11165451]
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: (3)
As of 2025-11-16 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 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.