Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: parse json

by frank1 (Monk)
on Sep 15, 2025 at 12:05 UTC ( [id://11166231]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11166231]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2026-01-21 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.