in reply to Iterate JSON File
Probably not the best way, but this works:
#!perl use strict; use warnings; use JSON::PP; my $json; { local $/ = undef; open my $fh, '<', 'in.json'; $json = <$fh>; close $fh; } my $final; my $decoded = decode_json($json); for my $ob ( @{$decoded->{observations}} ) { for my $status ( @{$ob->{status}} ) { for my $elem ( sort ( keys ( %{$status} ) ) ) { print $elem . "=" . $status->{$elem} . "\n"; } print "\n"; } }
and outputs ...
info=%(MinorFrameCnt)% kind=I path=_L7= stat=O info=%(Offset)% kind=I path=_L2= stat=O info=%(Period)% kind=I path=_L1= stat=O info=%(_L3)% = _L8 kind=I path=_L6=-1 stat=O info=_L3 = %(_L8)% kind=I path=_L6=-2 stat=O
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Iterate JSON File
by mijares93 (Initiate) on Aug 03, 2018 at 14:28 UTC | |
by AnomalousMonk (Archbishop) on Aug 03, 2018 at 15:27 UTC | |
by VinsWorldcom (Prior) on Aug 03, 2018 at 17:03 UTC |