G'day mijares93,

Welcome to the Monastery.

[Sorry, I'm a little late to the party on this one: I'm catching up after some travelling.]

The data returned from decode_json is typically a complex data structure and you can access its internal parts quite easily. Consider this short script:

#!/usr/bin/env perl use strict; use warnings; use autodie; use JSON; my $json_file = 'pm_1219718_data.json'; my $json_text = do { open my $fh, '<', $json_file; local $/; <$fh> }; my $perl_data = decode_json $json_text; for (@{$perl_data->{observations}[0]{status}}) { print "$_->{path}\n" }

Output:

_L7= _L2= _L1= _L6=-1 _L6=-2

The "$json_file" is what you posted plus

] }

to close the "observations" array (with the ']') and the JSON object as a whole (with the '}').

"... I am new to Perl ..."

Here's some suggested reading:

— Ken


In reply to Re: Iterate JSON File by kcott
in thread Iterate JSON File by mijares93

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.