DEV Community

Cover image for ESPN Data API: Extract Structured JSON in 2026
AlterLab
AlterLab

Posted on • Originally published at alterlab.io

ESPN Data API: Extract Structured JSON in 2026

This guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping.

TL;DR

Use AlterLab's Extract API to get structured JSON from ESPN pages by defining a schema for fields like team, score, date, venue and competition. Send a POST request with the URL and schema to receive validated, typed JSON output—no HTML parsing required.

Why use ESPN data?

Sports data powers real-time analytics, AI model training for game outcome prediction, and competitive intelligence for sports betting platforms. Developers build dashboards tracking team performance trends or monitor injury reports across leagues. Researchers correlate historical match data with social media sentiment for fan engagement studies. All require reliable, structured access to publicly listed game statistics.

What data can you extract?

From publicly accessible ESPN pages (e.g., scoreboards, team pages, event summaries), you can extract:

  • team: String (e.g., "Los Angeles Lakers")
  • score: String (e.g., "112-107")
  • date: String in ISO 8601 format (e.g., "2026-03-15T20:00:00Z")
  • venue: String (e.g., "Crypto.com Arena")
  • competition: String (e.g., "NBA Regular Season") These fields represent core game metadata available without authentication on standard ESPN URLs. Define additional fields in your schema as needed—AlterLab validates output types against your specification.

The extraction approach

Raw HTTP requests to ESPN return HTML filled with dynamic JavaScript-rendered content, embedded ads, and anti-bot measures. Parsing this with regex or brittle CSS selectors breaks when ESPN updates its frontend. AlterLab's Extract API handles headless browsing, JavaScript execution, and proxy rotation automatically. You receive clean JSON matching your schema—eliminating parsing logic and reducing maintenance overhead. This shifts focus from HTML gymnastics to data pipeline logic.

Quick start with AlterLab Extract API

First, install the AlterLab Python client via the Getting started guide. Then define your schema and call the extract endpoint.

```python title="extract_espn-com.py" {5-12}

client = alterlab.Client("YOUR_API_KEY")

schema = {
"type": "object",
"properties": {
"team": {
"type": "string",
"description": "The team field"
},
"score": {
"type": "string",
"description": "The score field"
},
"date": {
"type": "string",
"description": "The date field"
},
"venue": {
"type": "string",
"description": "The venue field"
},
"competition": {
"type": "string",
"description": "The competition field"
}
}
}

result = client.extract(
url="https://www.espn.com/nba/scoreboard/_/date/20260315",
schema=schema,
)
print(result.data)




The highlighted lines show schema definition and the extract call. For direct HTTP, use cURL:



```bash title="Terminal"
curl -X POST https://api.alterlab.io/v1/extract \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.espn.com/nba/scoreboard/_/date/20260315",
    "schema": {
      "properties": {
        "team": {"type": "string"},
        "score": {"type": "string"},
        "date": {"type": "string"},
        "venue": {"type": "string"},
        "competition": {"type": "string"}
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Both examples return JSON like:

{
  "team": "Los Angeles Lakers",
  "score": "112-107",
  "date": "2026-03-15T20:00:00Z",
  "venue": "Crypto.com Arena",
  "competition": "NBA Regular Season"
}
Enter fullscreen mode Exit fullscreen mode

Define your schema

The schema parameter uses JSON Schema Draft 07 to specify expected output types and structure. AlterLab validates the extracted data against this schema before returning results. If a field doesn't match (e.g., expecting a string but getting nested object), the API returns a validation error—preventing malformed data from entering your pipeline. Include descriptions for documentation; they don't affect validation but appear in AlterLab's interactive API explorer.

Handle pagination and scale

For high-volume extraction (e.g., scraping entire league schedules), use asynchronous jobs via AlterLab's batch endpoint. Group 100 URLs per request to stay within rate limits. Monitor costs using the pricing page—each extraction costs between $0.001 and $0.50 based on complexity. For recurring tasks, combine with AlterLab's scheduling feature to automate daily ESPN scoreboard pulls at 2 AM UTC.

```python title="batch_extract.py" {8-15}

client = alterlab.Client("YOUR_API_KEY")

urls = [
f"https://www.espn.com/nba/scoreboard/_/date/202603{str(i).zfill(2)}"
for i in range(1, 32)
]

async def extract_all():
tasks = []
for url in urls:
task = client.extract_async(
url=url,
schema={"properties": {"team": {"type": "string"}, "score": {"type": "string"}}}
)
tasks.append(task)
return await asyncio.gather(*tasks)

results = asyncio.run(extract_all())
for res in results:
print(res.data)




This async pattern processes multiple ESPN pages concurrently while respecting concurrency limits. Adjust batch size based on your API tier—check your dashboard for current limits.

## Key takeaways
- Define a strict JSON schema for ESPN fields to get typed, validation-guaranteed output
- Avoid HTML parsing fragility by using AlterLab's Extract API for JavaScript-rendered pages
- Start with single URL extraction, then scale using async batching for pipelines
- Always verify public data compliance with ESPN's robots.txt and Terms of Service
- Pay only per extraction—no minimums, no expiring credits

AlterLab transforms ESPN's public pages into reliable data APIs. Focus on building your sports analytics pipeline, not fighting anti-bot systems.
<div data-infographic="stats">
  <div data-stat data-value="99.2%" data-label="Extraction Accuracy"></div>
  <div data-stat data-value="1.4s" data-label="Avg Response Time"></div>
  <div data-stat data-value="100%" data-label="Typed JSON Output"></div>
</div>
<div data-infographic="steps">
  <div data-step data-number="1" data-title="Define Schema" data-description="Specify the fields you want as a JSON schema"></div>
  <div data-step data-number="2" data-title="Call Extract API" data-description="POST the URL + schema to AlterLab"></div>
  <div data-step data-number="3" data-title="Receive Typed JSON" data-description="Get back validated, structured data — no parsing needed"></div>
</div>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)