user786 has asked for the wisdom of the Perl Monks concerning the following question:
I want to parse the following json output :
My script executes a command and the command provides the json output
im using perl json module.
the output looks like below
[ { "wan" : 0, "lan" : 0, "name" : "HTTP", "wan1" : 0, "lan1" : 0 } ]
From my test script ,when i pass 'wan1' as argument i need to get 0 as the output
use stricts; use warning; use json; # function : sub get_stats { my ($self,$option) = @_; my $cmd = 'cmd'; #command goes here $self->execute($cmd); #$self->output() contains the json output. my $decoded = decode_json($self->output() ); my @out = @{ $decoded->{$self->output()} }; foreach my $line ($self->output( ) ); print $line -> {$option} . "\n" ; }
Function call
When the script executes it doesn't return anything. any suggestions please$self->{'stats_obj'} = Statistics->new( ip => "ip addr"); my $result = $self->{'stats_obj'}->get_stats('wan'); INFO('Status of the task is :' . $result );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parse Json using perl
by MidLifeXis (Monsignor) on May 21, 2015 at 16:00 UTC | |
Re: Parse Json using perl
by Corion (Patriarch) on May 21, 2015 at 16:01 UTC | |
Re: Parse Json using perl
by GrandFather (Saint) on May 22, 2015 at 11:26 UTC |