in reply to Re: parse json
in thread parse json

thanks i have got it working now, my reaming problem is only 1 to separate home and away team scores (results)

teams results are in "competitors":[{}]

"competitors":[ { "id":"379", "homeAway":"home", "score":"0", "records":[ { "name":"All Splits" } ], "team":{ "id":"379", "name":"Burnley", "links":[ { "rel":[ "clubhouse" ], "isHidden":false }, { "rel":[ "stats" ], "isHidden":false }, { "rel":[ "schedule" ], "isHidden":false }, { "rel":[ "squad" ], "isHidden":false } ], "venue":{ "id":"197" } }, "statistics":[ { "name":"appearances" } ] }, # Here is next curly braces for away team { "id":"364", "homeAway":"away", "score":"3", "records":[ { "name":"All Splits" } ], "team":{ "id":"364", "name":"Manchester City", "links":[ { "rel":[ "clubhouse" ], "isHidden":false }, { "rel":[ "stats" ], "isHidden":false }, { "rel":[ "schedule" ], "isHidden":false }, { "rel":[ "squad" ], "isHidden":false } ], "venue":{ "id":"192" } }, "statistics":[ { "name":"appearances" } ] } ],

Now i need some magic to separate curly braces for each team results and output this

90'+7': Burnley scored 0 status: 0 90'+7': Manchester City scored 3 status: 0

This is my working code

for my $match (@{$parse_json->{'events'}}) { my $elapsed = $match->{competitions}[0]{status}{displayClock}; my $status = $match->{competitions}[0]{wasSuspended}; # 0 false +/ 1 true | "wasSuspended":false, my $home = $match->{competitions}[0]{competitors}[0]{'team'}{n +ame}; my $away = $match->{competitions}[0]{competitors}[0]{'team'}{n +ame}; my $home_score = $match->{competitions}[0]{competitors}[0]{score}; my $away_score = $match->{competitions}[0]{competitors}[0]{score}; print "$elapsed: $home scored $home_score status: $status"; }

Replies are listed 'Best First'.
Re^3: parse json
by 1nickt (Canon) on Sep 15, 2025 at 12:34 UTC

    Is the home team always listed first, and the away team second?

    The second element of an array is at index position 1.

    So maybe

    my $home = $match->{competitions}[0]{competitors}[0]{'team'}{n +ame}; my $away = $match->{competitions}[0]{competitors}[1]{'team'}{n +ame}; my $home_score = $match->{competitions}[0]{competitors}[0]{score}; my $away_score = $match->{competitions}[0]{competitors}[1]{score};


    The way forward always starts with a minimal test.

      thank you so much, its working