in reply to parse json

Adding to Corion's answer: try this instead.

print $parse_json->{events}[0]{competitions}[0]{status}{displayClock};

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: parse json
by frank1 (Monk) on Sep 15, 2025 at 12:05 UTC

    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"; }

      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