Alabama has 71 NFL players, Duke 27 in the NBA. Mapping 5,111 pro rosters with ESPN's hidden JSON API
ESPN's website is built on a public JSON API. It has no docs and needs no key, and it covers scores, betting lines, standings, injury reports, rosters and news for the NFL, NBA, MLB, NHL, college sports and world soccer. I used it to pull every roster in the four major US leagues ( 5,111 players ) and answer some bar-argument questions. First, the endpoints. The endpoints Everything hangs off…
ESPN's website utilizes a public JSON API without requiring a key. This API provides scores, betting lines, standings, injury reports, rosters, and news for various sports including NFL, NBA, MLB, NHL, college sports, and world soccer. By leveraging this API, the author extracted every roster from the four major US leagues, totaling 5,111 players. This enabled the author to explore some intriguing questions.
The API structure is hierarchical, with endpoints organized under site.api.espn.com/apis/site/v2/sports/{sport}/{league}/. For NFL, the roster endpoint is /football/nfl/teams/{team_id}/roster, while the NBA roster endpoint is /football/nba/teams/{team_id}/roster. The API also offers other endpoints for scores, injuries, team lists, and news across different sports.
However, there are a few limitations to consider. A standard browser User-Agent is required to avoid a 403 error. Date ranges used in API calls may sometimes result in a 400 error. Loops should be executed day by day to avoid issues.
There are two shapes in which roster data is presented. NFL and NHL group players by unit, with each team's roster being an array of athletes. In contrast, NBA and MLB provide a flat list of players. To handle both shapes, the author demonstrated how to fetch the team data and then retrieve the players' details using appropriate fetch and JSON methods.
The scoreboard endpoint, which provides game details such as spread, total, and moneylines, was also examined. Additionally, the API can be used to uncover valuable insights about US college players. For instance, it reveals that Alabama has 71 NFL players, Ohio State has 67, Georgia has 66, and so on, with Duke having 27 NBA players.
Furthermore, the author analyzed the international representation within these leagues. In the NFL, only 3% of players are born outside the USA, primarily from Canada, Australia, and Nigeria. In contrast, the NBA is more diverse, with 22% of players born outside the USA, including players from France, Canada, Australia, and other countries.
The author also examined how many players had reported injuries at the time of the data snapshot. NFL players had a slightly higher injury rate at 21%, compared to NBA players at 20%. Other sports like MLB and NHL had lower injury rates, around 12%.
Average age varies across leagues, with the NBA having the youngest players at 25, followed by the NFL at 26, MLB at 27, and NHL at 28.
All the data, including player details such as team, position, age, height, weight, birthplace, college, experience, status, injury flag, is freely available on Kaggle at ESPN Sports Data. If users prefer a simpler approach, they can utilize the Apify platform to access the entire dataset. The possibilities are endless - from building a betting tool, to analyzing player demographics, or even creating a fantasy sports app, the potential applications of this dataset are vast.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to