in reply to Re: parse json
in thread parse json

this is my code below, am getting the results very well, my problem is parsing them, i tried this -> coz of an array but still cant parse out the message

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use JSON; my $url = 'link'; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, ); $ua->agent("MyApp/0.1"); my $req = HTTP::Request->new(GET => $url); my $response = $ua->request($req); my $parse_json = JSON::XS->new->decode ($response->content); if ($response->is_success) { for my $match (@{$parse_json->{leagues}}) { my $elapsed = $match->{events}->{competitions}->{status}{display +Clock}; my $status = $match->{events}->{competitions}->{wasSuspended}; my $home = $match->{events}->{competitors}->{team}; my $away = $match->{events}->{competitors}->{team}; my $away_goal = $match->{events}->{competitions}->{competitors}-> +{score}; my $home_goal = $match->{events}->{competitions}->{competitors}-> +{score}; print "$elapsed: $home: $home_goal: Suspended Match: $status"; print "$elapsed: $away: $away_goal: Suspended Match: $status"; } } else { print $response->decoded_content; print $response->status_line, "n"; }

Replies are listed 'Best First'.
Re^3: parse json
by Corion (Patriarch) on Sep 15, 2025 at 06:36 UTC

    You must be getting some kind of error message. What is the error message?

    Also, compare, manually, your code to your data structure:

    my $elapsed = $match->{events}->{competitions}->{status}{displayCloc +k} # HASH HASH HASH HASH

    Your data structure has array elements, for example events is an array.