DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › APIs

How to Extract Structured Data from Search Results with an API (2026 Guide)

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a search API as a typed data source: send the provider’s credentials and query, validate the JSON response, then map each result into fields your application owns. With Google’s Custom Search JSON API, that means an HTTP GET containing key, cx, and q, followed by parsing result fields such as title, link, snippet, and the optional pagemap. The important 2026 caveat is lifecycle: Google says the API is closed to new customers and existing customers must transition by January 1, 2027.

What you are extracting

A search-result API does not normally return a clean database record for every page on the web. It returns a provider-defined response that your code converts into an internal record. The basic record usually contains a result title, canonical-looking URL, and text snippet. Additional attributes—such as an author, date, rating, price, or other entity properties—appear only when the source page publishes usable markup and the provider exposes it.

As an Amazon Associate I earn from qualifying purchases.

That distinction determines your data model. Treat title, URL, and snippet as ordinary search-result fields. Treat richer values as optional observations. A missing rating is not the same as a rating of zero, and an absent author is not proof that the page has no author. Preserve the original URL, query, retrieval time, and provider response metadata so you can trace how each record was produced.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right search scope before writing code

“Structured data from search results” can mean several different products. Decide which one your application needs before selecting an API.

Requirement What the API must provide Important qualification
Search a controlled collection Domain or site restrictions and predictable indexing scope Google identifies Vertex AI Search as an option for searching up to 50 domains; it is not described as an equivalent full-web SERP API.
Collect broad search-page features Organic results plus any needed local, news, shopping, image, video, advertising, knowledge-graph, or answer features Confirm which result types are actually returned instead of assuming every provider exposes the same page layout.
Extract page entities Exposure of PageMap, metadata tags, JSON-LD, Microformats, RDFa, or Microdata Availability depends on both the markup on the crawled page and the provider’s extraction rules.
Build a compliance-sensitive product Documented storage, display, retention, geography, and commercial-use terms Search-result data is not automatically licensed for unrestricted republication or permanent storage.

Write down the minimum fields and result types you need. An internal site search, a market-monitoring dashboard, and a full search-page reconstruction have different scope, latency, and legal requirements.

Google Custom Search JSON API request anatomy

Google documents the Custom Search JSON API at https://www.googleapis.com/customsearch/v1. A request uses HTTP GET and requires three pieces of context:

  • key: your Google API key.
  • cx: the identifier of your Programmable Search Engine.
  • q: the search expression entered by your application or user.

A minimal request has this shape:

GET https://www.googleapis.com/customsearch/v1?key=YOUR_API_KEY&cx=YOUR_SEARCH_ENGINE_ID&q=structured+data+api

Keep credentials server-side. Do not place the API key in browser code, public repositories, analytics events, or URLs that you log without redaction. Build the query with a URL encoder rather than concatenating untrusted text manually.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configuration steps

  1. Define the collection. Configure a Programmable Search Engine for the domains or search context your application is allowed to query.
  2. Create or select the API credential. Store the key in a secret manager or protected environment variable. Give the calling service only the permissions it needs.
  3. Record the engine identifier. The value used as cx selects the configured search context; it is not interchangeable with the API key.
  4. Send a URL-encoded query. Pass the user’s search expression as q, and add only documented parameters that your engine and use case support.
  5. Capture the raw response during development. Save a redacted sample so your field mapping can be tested against optional and missing properties.

Understand the JSON response before mapping it

A successful response contains search metadata, engine metadata, and an items collection when results are available. Google’s reference describes result objects with fields including title, link, snippet, and pagemap. The exact object can contain more provider-specific fields, so map only what your application needs and preserve unknown fields only when you have a reason to do so.

Response area Typical use Handling rule
Query metadata Store the normalized query, pagination context, and request identity Keep it with the batch so a result can be traced back to the request that produced it.
Search information Display or log timing and estimated totals Google documents total-result counts as estimates; never present them as exact inventory.
Engine metadata Identify the configured search context Use it for diagnostics when multiple engines feed the same application.
items[] Iterate through returned results Handle a missing collection as “no returned items,” not as a parser crash.
title Human-readable result label Store as text and escape it when rendering HTML.
link Source URL Validate the value, retain it for provenance, and do not silently replace it with a guessed canonical URL.
snippet Search-result summary Keep it separate from page content; it is provider-generated context, not a complete extraction of the page.
pagemap Optional structured attributes extracted from page markup Expect the object, individual branches, or attributes to be absent.

Illustrative response shape

The following is a simplified example for field-mapping purposes, not a guarantee that every response contains every property:

{
  "searchInformation": {
    "formattedSearchTime": "0.42",
    "formattedTotalResults": "1280"
  },
  "items": [
    {
      "title": "Example result",
      "link": "https://example.test/article",
      "snippet": "A provider-generated summary of the page.",
      "pagemap": {
        "metatags": [
          { "author": "Example Author", "date": "2026-05-10" }
        ]
      }
    }
  ]
}

Do not infer that formattedTotalResults is a count you can use for pagination math. It is an estimate. Likewise, a pagemap branch is evidence that some markup was exposed for that result, not a promise that all pages use the same vocabulary.

Build a defensive extraction layer

Your parser should normalize provider output into a stable application schema while retaining enough provenance to audit decisions. A practical internal record can include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • provider and engine_id
  • query and request timestamp
  • rank within the returned item collection
  • title, url, and snippet
  • structured_data as a nullable object
  • the raw or hashed response identifier used for troubleshooting

Use explicit nulls for unavailable optional values. Keep arrays as arrays when the provider returns multiple authors, offers, images, or entities; collapsing them into one string makes later processing unreliable.

JavaScript example

const endpoint = "https://www.googleapis.com/customsearch/v1";

async function search(query, apiKey, engineId) {
  const url = new URL(endpoint);
  url.search = new URLSearchParams({
    key: apiKey,
    cx: engineId,
    q: query
  });

  const response = await fetch(url);
  const payload = await response.json();

  if (!response.ok) {
    throw new Error(`Search request failed (${response.status})`);
  }

  const items = Array.isArray(payload.items) ? payload.items : [];
  return items.map((item, index) => ({
    rank: index + 1,
    title: typeof item.title === "string" ? item.title : null,
    url: typeof item.link === "string" ? item.link : null,
    snippet: typeof item.snippet === "string" ? item.snippet : null,
    structuredData: item.pagemap && typeof item.pagemap === "object"
      ? item.pagemap
      : null
  }));
}

This layer checks the HTTP status, prevents a missing items array from breaking the request, and leaves absent structured data as null. Add your own URL policy before displaying links, such as allowing only https and rejecting schemes your application cannot safely render.

Python example

import os
import requests

ENDPOINT = "https://www.googleapis.com/customsearch/v1"

def search(query: str) -> list[dict]:
    response = requests.get(
        ENDPOINT,
        params={
            "key": os.environ["SEARCH_API_KEY"],
            "cx": os.environ["SEARCH_ENGINE_ID"],
            "q": query,
        },
        timeout=10,
    )
    response.raise_for_status()
    payload = response.json()

    results = []
    for rank, item in enumerate(payload.get("items", []), start=1):
        if not isinstance(item, dict):
            continue
        results.append({
            "rank": rank,
            "title": item.get("title"),
            "url": item.get("link"),
            "snippet": item.get("snippet"),
            "structured_data": item.get("pagemap"),
        })
    return results

In production, add bounded retries for transient failures, request correlation IDs, metrics for empty-result responses, and logging that removes API keys and sensitive query text. Do not retry indefinitely: a retry storm can amplify quota exhaustion and provider errors.

Separate ordinary result fields from page metadata

A title, URL, and snippet describe the search result. Structured page attributes come from markup or metadata that the provider recognized while crawling the source. Google’s Programmable Search Engine documentation lists PageMap, selected meta tags, estimated page dates, and rich-snippet formats including JSON-LD, Microformats, RDFa, and Microdata.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Extraction is conditional at every stage:

  • The page may not publish the field.
  • The markup may be invalid, ambiguous, or inconsistent across templates.
  • The provider may not expose the field in this API response.
  • The result may be stale relative to the current page.

For those reasons, do not use a search API as the sole authority for prices, ratings, publication dates, or identity-sensitive attributes. If a value affects a financial, safety, or eligibility decision, fetch and validate it through an appropriate first-party or domain-specific source under that source’s terms.

Use structured operators only when the markup supports them

Programmable Search Engine supports filtering, sorting or biasing, and numeric or date range restrictions over supported structured attributes. The operator must match the markup format.

Operation Documented input types Critical caveat
Attribute filtering Supported PageMap and metadata attributes Google states that attribute filtering is unavailable for JSON-LD.
Tree-branch filtering JSON-LD, Microformats, and RDFa branches The branch must exist in the returned structured tree; a missing branch yields no useful match.
Sorting or biasing Supported structured attributes Use only attributes with consistent values; sparse markup can produce unintuitive ordering.
Numeric or date ranges Supported numeric and date attributes Confirm how the provider interprets formats, time zones, and estimated dates before relying on the result set.

Estimated page dates deserve special care. Google documents that they are not added to PageMap and are not returned in the JSON API result fields described for PageMap. Do not write code that expects an estimated date to appear as an ordinary PageMap property.

Design the pipeline for missing and changing data

Validate at the boundary

Validate the response immediately after decoding JSON. Check that the top-level value is an object, that items is an array when present, and that each item is an object before reading fields. Reject malformed URLs and enforce maximum lengths for text that will enter a database or user interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preserve provenance

Store the query, engine identifier, provider, retrieval timestamp, rank, and source URL with each normalized record. If you later change extraction rules, you can explain which request produced a value and distinguish a provider change from a parser bug.

Version your schema

Optional fields and structured markup evolve. Version the normalized schema, keep a contract test containing responses with no items, missing snippets, empty PageMap branches, and multiple structured entities, and alert when a formerly common field drops sharply.

Handle pagination deliberately

Do not derive page counts from the estimated total-result value. Follow the provider’s documented pagination fields and stop when the response supplies no additional items, a configured maximum is reached, or your quota budget is exhausted.

Protect users and systems

  • Escape title and snippet text before inserting it into HTML.
  • Rate-limit user-controlled queries and cap query length.
  • Redact API keys and sensitive search terms from logs.
  • Apply timeouts and bounded retries.
  • Cache only when your provider terms and freshness requirements permit it.
  • Keep provider output separate from trusted application instructions; snippets can contain arbitrary text.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Google’s 2026 lifecycle and migration implications

Google’s official overview states that “The Custom Search JSON API is closed to new customers.” Existing customers have until January 1, 2027, to transition. That makes the API a maintenance or migration concern rather than a safe default for a new long-lived integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Situation Practical decision
You are an existing customer Inventory keys, engines, queries, stored fields, quotas, and downstream displays; create a migration plan that completes before January 1, 2027.
You need up to 50 defined domains Evaluate Vertex AI Search, which Google names as an alternative for that scope. Verify its fields, controls, pricing, and migration effort directly.
You need full-web search Google directs users to contact it about its full-web search solution. Do not assume the 50-domain alternative provides equivalent coverage.
You need search-page feature extraction Evaluate a provider that documents the result categories and fields you require, then test its schema with representative queries.

Google lists existing-customer terms of 100 queries per day at no charge, then $5 per 1,000 additional queries, up to 10,000 queries per day. Those figures are published for existing customers until the January 1, 2027 discontinuation, not as an offer to new customers. Confirm current eligibility and terms before budgeting.

How to compare another search API

A provider that returns JSON is not automatically interchangeable with Google’s response. Score candidates against the actual contract your application needs.

Comparison axis Questions to answer
Search scope Does it search the full web, a fixed domain set, or a provider-specific index?
Result categories Are organic, local, advertising, news, shopping, images, videos, knowledge-graph, and direct-answer results exposed separately?
Field coverage Which fields are guaranteed, which are optional, and how are absent values represented?
Structured-data handling Does the service expose PageMap, JSON-LD, Microformats, RDFa, Microdata, or only rendered result fields?
Geography and language Can you set location and language explicitly, and is location interpreted by country, region, city, coordinates, or IP?
Schema stability Are changes versioned and announced? Is there a test or sandbox response set?
Operations What are the rate limits, timeout expectations, retry guidance, latency commitments, and monitoring hooks?
Commercial and legal fit What storage, display, retention, redistribution, and automated-use rules apply?
Cost model Is billing per request, result type, location, volume tier, or another unit? What happens after a quota is reached?

SerpApi documents Google and Bing search API endpoints with structured JSON and lists categories such as organic, local, advertising, knowledge graph, direct answer, image, news, shopping, and video results. That documentation establishes the provider’s stated output categories; it does not establish equivalent quality, coverage, reliability, pricing, or legal permissions. Test any candidate against your own queries and acceptance criteria.

Troubleshooting common extraction failures

The response has no items array

Treat this as an empty result set only after checking the HTTP status and error payload. A successful response can contain metadata without returned items; an error response may have a different shape entirely. Keep the status code and a redacted error identifier in logs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

pagemap is missing or empty

Your parser is not necessarily broken. The page may lack supported markup, the provider may not expose that markup for this result, or the structured branch may be unavailable in the current crawl. Keep ordinary fields and represent structured data as null.

A filter returns unexpected results

Check that the operator matches the markup type. In particular, Google documents that attribute filtering is unavailable for JSON-LD, while tree-branch filtering is available for JSON-LD, Microformats, and RDFa. Also verify that the attribute is populated consistently rather than present on only a few pages.

Totals do not match your database

Search-result totals are estimates, not an exact inventory. Use returned items and documented pagination controls for processing, and label any displayed total as an estimate.

The integration works but cannot be adopted

Check lifecycle status, eligibility, quota, geography, retention, and display terms before investing in a production rollout. A technically valid parser does not solve a provider transition deadline or a use that the provider does not permit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A production-readiness checklist

  • Scope is documented as full-web-style search or a defined domain collection.
  • Credentials are stored outside source code and logs.
  • Queries are URL-encoded, length-limited, and rate-limited.
  • HTTP status, timeout, JSON decoding, and provider error handling are separate checks.
  • Missing items, title, link, snippet, and pagemap values are handled explicitly.
  • Estimated totals are labeled as estimates.
  • Normalized records retain query, rank, source URL, provider, engine, and retrieval time.
  • HTML output escapes provider text and validates link schemes.
  • Structured attributes are treated as optional and stale-prone.
  • Operator and markup-format compatibility has been tested.
  • Quota, pricing, retention, display, and redistribution terms are confirmed for the intended geography and use.
  • Existing Google customers have a migration plan before January 1, 2027; new projects have evaluated alternatives instead of assuming access.

The Bottom Line

The reliable pattern is to normalize the API’s ordinary result fields first, treat page-level structured metadata as optional, and preserve provenance for every value. In 2026, verify eligibility and lifecycle before choosing Google’s Custom Search JSON API: new customers are closed out, and existing customers face a January 1, 2027 transition deadline.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

APIsGoogle Custom SearchJSONSearchstructured dataWeb development

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.