Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Iterate JSON File

by kcott (Archbishop)
on Aug 06, 2018 at 06:45 UTC ( [id://1219918]=note: print w/replies, xml ) Need Help??


in reply to Iterate JSON File

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-28 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found