US Census Data API: Extract Structured JSON in 2026
Tutorials

US Census Data API: Extract Structured JSON in 2026

Learn how to extract structured US Census data via API with AlterLab. Define a schema and receive typed JSON output.

3 min read
4 views

AlterLab handles this automaticallyscrape any URL with one API call. No infrastructure required.

Try it free

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

TL;DR

Extract US Census data via AlterLab’s Extract API by defining a JSON schema for title identifier date_published category and description. The API returns typed JSON and handles compliance automatically.

Why use US Census data?

AI training pipelines often need large labeled datasets. Analytics teams use census figures for market research. Competitive intelligence tools monitor demographic trends. All of these use cases benefit from structured JSON that can be ingested directly into downstream models.

What data can you extract?

Public census pages expose fields that are safe to scrape. Typical fields include:

  • title – the headline of the release
  • identifier – a unique code such as a tract ID
  • date_published – the publication timestamp
  • category – the subject area like population or housing
  • description – the full text summary

These fields are always presented in plain HTML. No personal identifiers are included.

The extraction approach

Raw HTTP requests followed by HTML parsing are brittle. Websites change their markup and anti bot systems block simple crawlers. A data API sits above the page load layer. It handles rendering proxy rotation and schema validation. The result is reliable typed output without writing fragile selectors.

Quick start with AlterLab Extract API

The following Python snippet shows a minimal extract call. Replace YOUR_API_KEY with your key.

Python
import alterlab

client = alterlab.Client("YOUR_API_KEY")

schema = {
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "description": "The title field"
    },
    "identifier": {
      "type": "string",
      "description": "The identifier field"
    },
    "date_published": {
      "type": "string",
      "description": "The date published field"
    },
    "category": {
      "type": "string",
      "description": "The category field"
    },
    "description": {
      "type": "string",
      "description": "The description field"
    }
  }
}

result = client.extract(
    url="https://census.gov/data/2024/acs/acs5?get=NAME,B01001_001E",
    schema=schema,
)
print(result.data)

The matching cURL example lets you test the endpoint from the command line.

Bash
curl -X POST https://api.alterlab.io/v1/extract \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://census.gov/data/2024/acs/acs5?get=NAME,B01001_001E",
    "schema": {"properties": {"title": {"type": "string"}, "identifier": {"type": "string"}, "date_published": {"type": "string"}}}
  }'

Both examples hit the same endpoint described in the AlterLab Extract API documentation. See the full guide for authentication details.

Define your schema

The schema you provide tells AlterLab which fields to extract and what type to expect. The platform validates the returned JSON against this schema and rejects mismatches. This guarantees that downstream code can rely on the presence and type of each field.

JSON
{
  "type": "object",
  "properties": {
    "title": {"type": "string"},
    "identifier": {"type": "string"},
    "date_published": {"type": "string"},
    "category": {"type": "string"},
    "description": {"type": "string"}
  }
}

When you call the API with this schema AlterLab returns a JSON object that matches the structure exactly. No post processing is required.

Handle pagination and scale

Large census releases span multiple pages. Use batch requests to process many URLs in parallel. The following async example shows how to queue several URLs and wait for all results.

Python
import asyncio
import alterlab

async def extract_one(url, schema):
    client = alterlab.Client("YOUR_API_KEY")
    return await client.extract(url=url, schema=schema)

async def main():
    urls = [
        "
Share

Was this article helpful?

Frequently Asked Questions

The US Census provides an official API for some datasets but many public pages lack structured access. AlterLab fills the gap by extracting publicly available data and returning typed JSON.
You can extract fields such as title identifier date_published category and description from any publicly listed page. The output matches the schema you define.
Cost is pay as you go. A minimum of $0.001 applies and the maximum per request is $0.50. Pricing details are on the AlterLab pricing page.