# Structured data: read the JSON-LD a page already carries, from

Many pages describe themselves in a JSON-LD block that is plain JSON, with no selectors needed. See what eight public pages carried on 2026-11-21, and what to do when a page has none.

Canonical: https://spider.cloud/learn/structured-data/

Structured data is a block of facts a page states about itself in a fixed vocabulary, and the most common form is JSON-LD: plain JSON inside a `<script type="application/ld+json">` tag. When a page has one, you can read its title, type, dates or price with a JSON parser instead of writing a selector for each field.

Site owners add these blocks mainly for search engines, so the data is there for any client that reads the HTML. This page explains what a block holds, shows a short Python script that finds them, and lists what eight public pages carried on one day. Most of them carried nothing, and that is worth knowing before you plan around it. When the block is there, a [web scraping](/web-scraping/) job can read it with a JSON parser and needs no selector.

## What JSON-LD is

The W3C standard opens with a one-line definition: "JSON-LD is a lightweight syntax to serialize Linked Data in" JSON. The next sentence is the part that matters to a scraper: "Its design allows existing JSON to be interpreted as Linked Data with minimal changes." Read the block with `json.loads` and you get dictionaries and lists. The linked data part is optional for you.

The same standard says how a block sits in a page. You place it in a script element with the `type` attribute set to `application/ld+json`, and the browser treats it as data, not code. It never runs and never shows on screen. A page may hold several such blocks.

Google describes the purpose from the site owner's side: "Structured data is a standardized format for providing information about a page and classifying the page content". The vocabulary most sites use is schema.org, which is where names like `Article`, `Product`, `Recipe` and `BreadcrumbList` come from. Each item names its kind in an `@type` key, and a block that holds several items often wraps them in a list under `@graph`.

Google accepts three formats, JSON-LD, Microdata and RDFa, and states its preference: "In general, Google recommends using JSON-LD for structured data if your site's setup allows it". Microdata and RDFa sit in attributes spread through the visible HTML, so they need a different parser. This page covers JSON-LD only.

## A script that finds the blocks

The script below sends the addresses to `/scrape` in one call, asks for the raw HTML, and pulls out every JSON-LD block with the HTML parser in Python's standard library. For each page it prints the status, the number of blocks, how many failed to parse as JSON, and every `@type` it found, including the ones inside `@graph`.

```python
"""Fetch pages through the Spider API and list the JSON-LD each one carries.

    python3 read_jsonld.py URL [URL ...]

For every page it prints the status, how many JSON-LD blocks it holds, and the
@type of each item in them. A block that is not valid JSON is counted and named.
"""
import json
import os
import sys
import urllib.request
from html.parser import HTMLParser

API = "https://api.spider.cloud/scrape"


class LdFinder(HTMLParser):
    """Collect the text of every <script type="application/ld+json">."""

    def __init__(self):
        super().__init__()
        self.blocks, self._buf = [], None

    def handle_starttag(self, tag, attrs):
        kind = (dict(attrs).get("type") or "").strip().lower()
        if tag == "script" and kind == "application/ld+json":
            self._buf = []

    def handle_data(self, data):
        if self._buf is not None:
            self._buf.append(data)

    def handle_endtag(self, tag):
        if tag == "script" and self._buf is not None:
            self.blocks.append("".join(self._buf))
            self._buf = None


def types_in(node):
    """Yield every @type in a JSON-LD value, including items inside @graph."""
    if isinstance(node, list):
        for item in node:
            yield from types_in(item)
    elif isinstance(node, dict):
        t = node.get("@type")
        if t:
            yield from (t if isinstance(t, list) else [t])
        yield from types_in(node.get("@graph", []))


def main() -> int:
    urls = sys.argv[1:]
    key = os.environ.get("SPIDER_API_KEY")
    if not urls or not key:
        print("usage: SPIDER_API_KEY=... python3 read_jsonld.py URL [URL ...]")
        return 1

    body = json.dumps({"url": ",".join(urls), "request": "http", "return_format": "raw"}).encode()
    req = urllib.request.Request(API, data=body, headers={
        "Authorization": f"Bearer {key}",
        "Content-Type": "application/json",
    })
    with urllib.request.urlopen(req, timeout=90) as resp:
        pages = json.load(resp)

    for page in pages:
        finder = LdFinder()
        finder.feed(page.get("content") or "")
        types, bad = [], 0
        for text in finder.blocks:
            try:
                types.extend(types_in(json.loads(text)))
            except ValueError:
                bad += 1
        print(page.get("url"))
        print(f"  status {page.get('status')}, blocks {len(finder.blocks)}, not json {bad}")
        print(f"  types {', '.join(types) if types else '-'}")
    return 0


if __name__ == "__main__":
    sys.exit(main())
```

It uses `request: http`, a plain fetch with no browser. That choice shapes the result, as the next section shows.

## Eight pages, one run

We ran the script on 2026-11-21 at 15:17:35 UTC with eight addresses: an encyclopedia article, two documentation pages, a language home page, a code repository, a package page, a page on a practice site built for scraping, and a government guidance page. This is what it printed, unchanged. The pages come back in the order they finished, not the order we sent them.

```text
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
  status 200, blocks 0, not json 0
  types -
https://en.wikipedia.org/wiki/Web_scraping
  status 200, blocks 1, not json 0
  types Article
https://www.python.org/
  status 200, blocks 1, not json 0
  types WebSite
https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data
  status 200, blocks 1, not json 0
  types BreadcrumbList
https://github.com/rust-lang/rust
  status 200, blocks 0, not json 0
  types -
https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html
  status 200, blocks 0, not json 0
  types -
https://www.npmjs.com/package/puppeteer
  status 200, blocks 0, not json 0
  types -
https://www.gov.uk/guidance/data-protection-in-schools
  status 503, blocks 0, not json 0
  types -
```

This clip counts the same run, page by page.

Read the JSON-LD a page already has. 1 min 9 s, no sound. The words are on screen, and the captions button shows them at your own text size.

Read the transcript

Read the JSON-LD a page already has. A block of plain JSON in the HTML, and how many pages carried one.

A JSON-LD block is plain JSON in a script tag. A JSON parser reads it. \<script type="application/ld+json">: the tag a block sits in. if tag == "script" and kind == "application/ld+json": types.extend(types_in(json.loads(text))): a JSON parser reads it. t = node.get("@type"): each item names its kind. yield from types_in(node.get("@graph", \[])): items in a list. 3: blocks the script found in this run. 0: of them failed to parse as JSON.

Of 8 pages asked, 7 answered and 3 carried a block. 3 answered and carried a block. 4 answered with no block. 1 answered 503, so it says nothing. 8: pages asked, one plain fetch each. 7: answered. 3: carried a block.

Each of the 3 blocks names the kind of page, for a search result. en.wikipedia.org states Article. www\.python.org states WebSite. developers.google.com states BreadcrumbList. 4 more answered with no block, and 1 did not answer. 3: types, each describing the page.

4 answered with no block, a product page among them. developer.mozilla.org: a documentation page. github.com: a code repository. books.toscrape.com: a product page on a practice site. www\.npmjs.com: a package page. A plain fetch reads only the HTML the server sent.

Check for a block first. Do not plan on finding one. What most pages carried: a JSON-LD block?. block: Parse it with a JSON parser. none: Write selectors after all. 503: No answer. It says nothing. This run: none.

Read the full page. The page is at spider.cloud/learn/structured-data.

## What the eight show

Seven pages answered. The government page answered 503, which means the server could not serve it at that moment, so it tells us nothing about structured data. We did not retry it.

Three of the seven carried a block, one each, and every block parsed as JSON. Four carried none. The three types say a lot about why sites add the data. The encyclopedia page says it is an `Article`, the language home page says it is a `WebSite`, and the Google page gives only a `BreadcrumbList`, the trail of sections above it. None of them states the facts you would most likely want from that page, such as a price or a list of versions. Each block describes the page for a search result, and that is all.

The book page is the useful warning. A product page with a title, a price and a stock count is exactly where you might expect a `Product` block, and this one has none. The site was built for practice and shows its data only in the visible HTML. Many real shops are the same. When the block is missing, you write selectors after all; the [XPath and CSS selectors page](/learn/xpath-vs-css/) shows both ways, and the [structured JSON extraction guide](/guides/structured-json-extraction-from-pages/) does it in one API call.

The run also has a blind spot. Google notes that it "can read JSON-LD data when it is" added later by JavaScript on the page. A plain HTTP fetch sees only the HTML the server sent, so a page that adds its block from a script would show zero here. That may be true of some of the four empty pages, and this run cannot tell. If you need those blocks, fetch the page with a browser and read the HTML after the scripts have run.

We picked these eight pages because they are public and allow reading, so the counts describe this set and no other.

## Do this, avoid this

### Do this

- Check for a JSON-LD block before you write selectors. If it holds the fields you need, parse it with a JSON parser.
- Read every block on the page and walk the @graph list, since one page can hold several items.
- Compare a field from the block with the visible page once, because the block can lag behind the text.
- Read the site's robots.txt and terms before you collect from it, the same as for any other field.

### Avoid this

- Planning a job around JSON-LD before you have run the script on its pages. Four of seven pages that answered in this run had no block.
- Giving up on a page because the block is missing. A script may add it after load.
- Stopping at the block when the field you need is only in the visible page. The block holds what the owner chose to state for search.
- Keeping personal data from a block, such as an author's contact details, without a lawful reason to hold it.

## Read a block yourself

Save the script as `read_jsonld.py`, set `SPIDER_API_KEY`, and run it with one address you are allowed to fetch: `python3 read_jsonld.py https://en.wikipedia.org/wiki/Web_scraping`. To see the block itself, print `text` inside the loop before it is parsed. If the page shows `blocks 0`, the [glossary](/learn/glossary/) explains the terms the selector pages use, and the next step is to pick the fields out of the HTML.

## Sources

1. [W3C, JSON-LD 1.1, Recommendation of 16 July 2020](https://www.w3.org/TR/json-ld11/) Read November 21, 2026
2. [Google Search Central, Introduction to structured data markup in Google Search](https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data) Read November 21, 2026
