Hi, when trying to access nested elements of data structures using key "paths" as you have, I usually turn to a JSON pointer. I find Mojo::JSON::Pointer easiest to use. In the following demonstration I am being lazy and returning your Dumper dump from a sub and then converting it back to JSON. If you are using LWP::UserAgent's decoded_content() you will already have the structure in $data below.

use v5.014; use JSON; use Mojo::JSON::Pointer; # reconstructing a JSON response from your Dump my $json = to_json( get_response() ); # your client request gets this # converting your API response to a Perl struct my $data = from_json( $json ); # your client should provide this # converting the elements to JSON pointer paths my @elements = map {s!\.!/!gr} (qw/ userName displayName meta.created +/); for my $item ( @{ $data->{Resources} } ) { my $pointer = Mojo::JSON::Pointer->new( $item ); foreach my $element (@elements) { say "$element: " . $pointer->get('/' . $element); } say ''; } sub get_response { return { 'Resources' => [{ 'displayName' => 'User 1', 'userName' => 'user1@test.com', 'id' => '1234567', 'meta' => { 'created' => '2018-04-16T11:5 +7:19.376Z' } }, { 'displayName' => 'User 2', 'userName' => 'user2@test.com', 'id' => '1234568', 'meta' => { 'created' => '2018-04-16T11:5 +9:27.111Z' } }, { 'displayName' => 'User 3', 'userName' => 'user3@test.com', 'id' => '12345679', 'meta' => { 'created' => '2018-11-21T14:4 +9:33.821Z' } }, ], 'totalResults' => 3, 'itemsPerPage' => 50, 'startIndex' => 1, 'schemas' => [ 'urn:ietf:params:scim:api:messages:2.0:ListRe +sponse' ] }; } __END__
Output:
perl 1226873.pl userName: user1@test.com displayName: User 1 meta/created: 2018-04-16T11:57:19.376Z userName: user2@test.com displayName: User 2 meta/created: 2018-04-16T11:59:27.111Z userName: user3@test.com displayName: User 3 meta/created: 2018-11-21T14:49:33.821Z

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Dynamic Dereferencing by 1nickt
in thread Dynamic Dereferencing by Flip76

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.