Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:21:24+00:00 2026-06-16T22:21:24+00:00

Im experimenting with the espn public API and am trying to use their json

  • 0

Im experimenting with the espn public API and am trying to use their json to access NFL player information.

the json im accessing succesfully looks like:

{
"sports": [
    {
        "name": "football",
        "id": 20,
        "leagues": [
            {
                "name": "National Football League",
                "abbreviation": "nfl",
                "id": 28,
                "groupId": 9,
                "shortName": "NFL",
                "athletes": [
                    {
                        "id": 14466,
                        "firstName": "Isa",
                        "lastName": "Abdul-Quddus",
                        "fullName": "Isa Abdul-Quddus",
                        "displayName": "Isa Abdul-Quddus",
                        "shortName": "I. Abdul-Quddus",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466/news/notes"
                                }
                            },
                            "web": {
                                "athletes": {
                                    "href": "http://espn.go.com/nfl/player/_/id/14466/isa-abdul-quddus?ex_cid=espnapi_public"
                                }
                            },
                            "mobile": {
                                "athletes": {
                                    "href": "http://m.espn.go.com/nfl/playercard?playerId=14466&ex_cid=espnapi_public"
                                }
                            }
                        }
                    },
                    {
                        "id": 8645,
                        "firstName": "Hamza",
                        "lastName": "Abdullah",
                        "fullName": "Hamza Abdullah",
                        "displayName": "Hamza Abdullah",
                        "shortName": "H. Abdullah",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645/news/notes"
                                }
                            },
                            "web": {
                                "athletes": {
                                    "href": "http://espn.go.com/nfl/player/_/id/8645/hamza-abdullah?ex_cid=espnapi_public"
                                }
                            },
                            "mobile": {
                                "athletes": {
                                    "href": "http://m.espn.go.com/nfl/playercard?playerId=8645&ex_cid=espnapi_public"
                                }
                            }
                        }
                    },
                    {
                        "id": 11910,
                        "firstName": "Husain",
                        "lastName": "Abdullah",
                        "fullName": "Husain Abdullah",
                        "displayName": "Husain Abdullah",
                        "shortName": "H. Abdullah",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910/news/notes"
                                }
                            } ........
                ]
            }
        ]
    }
],
"resultsOffset": 0,
"resultsLimit": 50,
"resultsCount": 3301,
"timestamp": "2013-01-06T19:30:17Z",
"status": "success"

}

and heres the html / javascript Im using:

$(document).ready(function(){

    $.getJSON("http://api.espn.com/v1/sports/football/nfl/athletes?apikey=MY-API-KEY-HERE&_accept=application/json",
    function(data){
      $.each(data["sports"], function(i,item){
         $("#infoDiv").append( [i] + " - " + item.name + "<br>" );    
      });
    });

});

i can get this to display 0 – football but cant use something like

$.each(data["sports"]["leagues"]["athletes"], function(i,item){
  $("#infoDiv").append( [i] + " - " + item.firstName + "<br>" );  

to access the individual athlete data such as item.firstName , etc.

i keep getting the following error:

TypeError: data.sports.leagues is undefined

what am I missing? I’m using this same code structure successfully with a couple of other API’s that provide json. the ESPN json is a little more complex in comparison though.

thanks for any light you can shed on this for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:21:25+00:00Added an answer on June 16, 2026 at 10:21 pm

    sports, leagues and athletes are arrays, for example: sports[0] is an object (the one with name=’football’)
    You should iterate each like this (not tested):

    $.each(data.sports, function(i,sport) {
        $.each(sport.leagues, function(i,league) {
            $.each(league.athletes, function(i,athlete) {
                $("#infoDiv").append( [i] + " - " + athlete.firstName + "<br>" );
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I experimenting with twitter streaming API, I use Phirehose to connect to twitter and
I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to
I am experimenting with the chrome.extension API. manifest.json { name: First, version: 1.0, manifest_version:
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
I'm experimenting with ASP.Net Web API, which, by convention, splits controller methods into a
Currently experimenting with the FB GRAPH API Explorer Tool for the purpose of searching
In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an
Experimenting with git, I've setup Gitlab for a self hosted repository and it looks
After experimenting with many IMAP API's, I have decided to write my own (Most
After experimenting with composite operations and drawing images on the canvas I'm now trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.