frank1 has asked for the wisdom of the Perl Monks concerning the following question:
i need some help on parsing some json msg, am doing a get request and getting the json output, but need help in parsing it and separating both teams with thier scores in declosed "competitors": {}, {}
this is my json output
{ "leagues": [ { "id": "700", "season": { "year": 2025, "type": { "id": "1", "type": 13481 } }, "logos": [ { "width": 500, "height": 500, "rel": [ "full", "default" ], "lastUpdated": "2019-05-08T16:07Z" }, { "width": 500, "height": 500, "rel": [ "full", "dark" ], "lastUpdated": "2021-08-10T20:43Z" } ], "calendarType": "day", "calendar": [ "2025-08-15T07:00Z" ] } ], "events": [ { "id": "740633", "season": { "year": 2025, "type": 13481 }, "competitions": [ { "id": "740633", "status": { "clock": 540, "displayClock": "9'", "period": 1, "type": { "id": "25", "shortDetail": "9'" } }, "venue": { "id": "197", "fullName": "Turf Moor", "address": { "country": "England" } }, "format": { "regulation": { "periods": 2 } }, "notes": [], "geoBroadcasts": [], "broadcasts": [], "broadcast": "", "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" } ] }, { "id": "364", "homeAway": "away", "score": "0", "records": [ { "name": "All Splits" } ], "team": { "id": "364", "name": "Liverpool", "links": [ { "rel": [ "clubhouse" ], "isHidden": false }, { "rel": [ "stats" ], "isHidden": false }, { "rel": [ "schedule" ], "isHidden": false }, { "rel": [ "squad" ], "isHidden": false } ], "venue": { "id": "192" } }, "statistics": [ { "name": "appearances" } ] } ], "details": [], "odds": [ { "provider": { "id": "2000" }, "awayTeamOdds": { "summary": "1/3", "team": { "id": "364" }, "link": { "language": "en-GB", "rel": [ "away" ], "isHidden": false } }, "homeTeamOdds": { "summary": "8/1", "team": { "id": "379" }, "link": { "language": "en-GB", "rel": [ "home" ], "isHidden": false } }, "drawOdds": { "summary": "4/1", "link": { "language": "en-GB", "rel": [ "draw" ], "isHidden": false } } } ], "wasSuspended": false, "playByPlayAvailable": true, "playByPlayAthletes": true } ], "status": { "clock": 540, "displayClock": "9'", "period": 1, "type": { "id": "25", "shortDetail": "9'" } }, "venue": { "displayName": "Turf Moor" }, "links": [ { "language": "en-GB", "rel": [ "live" ], "isHidden": false }, { "language": "en-GB", "rel": [ "stats" ], "isHidden": false } ] } ] }
this is my part of script i want to fix, and output all teams with the scores
for my $match (@{$parse_json->{leagues}}) { my $elapsed = $match->{competitions}{status}{displayClock}; my $status = $match->{wasSuspended}; my $home = $match->{competitors}{team}{homeAway}; my $away = $match->{competitors}{team}{homeAway}; my $away_goal = $match->{competitors}{score}; my $home_goal = $match->{competitors}{score}; print "$elapsed: $home: $home_goal: Suspended Match: $status"; print "$elapsed: $away: $away_goal: Suspended Match: $status"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: parse json
by choroba (Cardinal) on Sep 14, 2025 at 22:28 UTC | |
by frank1 (Monk) on Sep 15, 2025 at 12:05 UTC | |
by 1nickt (Canon) on Sep 15, 2025 at 12:34 UTC | |
by frank1 (Monk) on Sep 15, 2025 at 13:00 UTC | |
Re: parse json
by Corion (Patriarch) on Sep 14, 2025 at 17:53 UTC | |
by frank1 (Monk) on Sep 14, 2025 at 19:15 UTC | |
by Corion (Patriarch) on Sep 15, 2025 at 06:36 UTC |