Sub topic 10
Add Structured Data That Matches the Visible Page
This chapter assumes you can read basic HTML and JSON, and that you already know how headings, lists, and tables are marked up on a page. It covers JSON-LD, a way to describe your page's content to machines. It also covers where JSON-LD helps, where it does not, and the mistakes that cause it to be ignored.
What structured data is and what it is not
Structured data is a block of machine-readable text that states facts about a page in a fixed vocabulary. The vocabulary most sites use is schema.org. The most common format is JSON-LD (JSON for Linked Data), which sits in a <script type="application/ld+json"> element and is not displayed to readers.
The visible page is for people. The structured data is a second description of the same content for software. Search engines and other crawlers may read it to confirm what a page is about, and some use it to qualify a page for special result displays.
Structured data does not guarantee anything. It does not make a page appear in an AI answer, and it does not guarantee a citation. Systems that retrieve and quote content decide what to use based on many signals, and the visible text remains the primary material. Treat JSON-LD as optional support for a page that is already well structured.
How structured data relates to the visible page
The rule for this whole chapter is that the structured data must mirror the visible content. If a value appears in the JSON-LD, a reader must be able to find the same value on the page.
This rule exists for three reasons:
- Search engines publish guidelines that tell site owners not to mark up content that users cannot see. Pages that break this rule can lose eligibility for enhanced results.
- Data that disagrees with the page creates conflicts. If the JSON-LD says a plan costs $10 and the page says $12, a system has no reliable way to know which is current.
- Hidden data goes stale. People update visible text and forget the script block.
Anatomy of a JSON-LD block
Every JSON-LD block has three kinds of keys you will use again and again.
@contextnames the vocabulary. For schema.org, it ishttps://schema.org.@typenames the kind of thing described, such asFAQPage,Article, orHowTo.- Other keys are properties defined by that type, such as
name,text, ormainEntity.
Here is a minimal block for a page with one question and answer.
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What does a factory reset do?",
"acceptedAnswer": {
"@type": "Answer",
"text": "It erases all saved settings and restores the default configuration."
}
}
]
}
</script>The matching visible section would look like this.
<h2>What does a factory reset do?</h2>
<p>A factory reset erases all saved settings and restores the router to its default configuration.</p>The question text in name equals the visible heading. The answer in text is a faithful short version of the visible paragraph. A reader who compares the two sees the same claim.
This pairing also shows why question-style headings and answer-first paragraphs from earlier chapters make structured data easy. When each section already opens with its answer, the JSON-LD can copy that opening sentence with little editing.
Choosing a type
Pick a type that describes what the page really is. Do not pick a type because it is known to trigger a display feature.
| Type | Use it when | Visible content it must match |
|---|---|---|
| Article | The page is a news story, blog post, or guide | Headline, author, and dates shown on the page |
| FAQPage | The page lists questions with answers written by the site | Each question and its answer, shown in full |
| HowTo | The page gives ordered steps toward a result | The steps, in the same order |
| Product | The page describes one item for sale | Name, price, and availability shown to shoppers |
| BreadcrumbList | The page shows a breadcrumb trail | The trail links as displayed |
Support for these types changes over time. Search engines have narrowed which types produce visible enhancements. For example, Google has limited FAQ and HowTo displays to a small set of sites or removed them. Check the current documentation of the search engine you care about before investing effort. The types remain valid schema.org vocabulary, and other consumers may still read them.
Mirroring a how-to page
Suppose a page has this ordered list.
<h2>How do I factory reset the router?</h2>
<p>Hold the reset button for about 10 seconds until the lights blink.</p>
<ol>
<li>Power on the router and wait for it to finish starting.</li>
<li>Press and hold the reset button for 10 seconds.</li>
<li>Release the button and wait for the router to restart.</li>
<li>Sign in with the default credentials printed on the label.</li>
</ol>A matching HowTo block repeats the same four steps in the same order.
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "HowTo",
"name": "How to factory reset the router",
"step": [
{
"@type": "HowToStep",
"position": 1,
"text": "Power on the router and wait for it to finish starting."
},
{
"@type": "HowToStep",
"position": 2,
"text": "Press and hold the reset button for 10 seconds."
},
{
"@type": "HowToStep",
"position": 3,
"text": "Release the button and wait for the router to restart."
},
{
"@type": "HowToStep",
"position": 4,
"text": "Sign in with the default credentials printed on the label."
}
]
}
</script>Notice that the step text is copied from the list items. If someone edits step 2 on the page, the JSON-LD must change as well.
Keep the two in sync by generating one from the other
Manual copying is the most common source of drift. A safer approach is to produce the JSON-LD from the same data that renders the page. The Python script below builds an FAQ block from a list of question and answer pairs, and also renders the matching HTML, so both always agree.
import json
from html import escape
faqs = [
(
"What does a factory reset do?",
"It erases all saved settings and restores the default configuration.",
),
(
"When is a factory reset not needed?",
"A simple restart fixes most connection problems without erasing settings.",
),
]
def render_html(items):
parts = []
for question, answer in items:
parts.append(f"<h2>{escape(question)}</h2>")
parts.append(f"<p>{escape(answer)}</p>")
return "\n".join(parts)
def render_json_ld(items):
data = {
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": question,
"acceptedAnswer": {"@type": "Answer", "text": answer},
}
for question, answer in items
],
}
body = json.dumps(data, indent=2).replace("</", "<\\/")
return f'<script type="application/ld+json">\n{body}\n</script>'
print(render_html(faqs))
print(render_json_ld(faqs))Two details matter. json.dumps produces valid JSON, so you avoid trailing commas and unescaped quotes that break hand-written blocks. The replace("</", "<\\/") step prevents a stray </script> inside a string from closing the element early.
Common errors
These problems appear often in real audits.
- Marking up hidden content. The JSON-LD lists questions that exist nowhere on the page, or answers that appear only in a collapsed element no reader can open.
- Mismatched values. Prices, dates, or step order differ between the page and the block.
- Wrong type for the page. A product page labelled
FAQPage, or a forum thread labelledHowTo. - Invalid JSON. A trailing comma, a smart quote, or a missing brace makes the whole block unreadable. Parsers skip it without telling visitors.
- Duplicate or conflicting blocks. A plugin and a theme each add an
Articleblock with different headlines. - Promotional text in answers. Stuffing marketing copy into
acceptedAnswermakes the answer unhelpful. - Treating it as a ranking switch. Adding JSON-LD and expecting citations. It does neither on its own.
Validating your markup
Validate in two steps. First, check that the JSON parses. Second, check that the content matches the page.
The script below finds JSON-LD blocks in an HTML string, confirms each one parses, and checks that every Question name appears in the visible text.
import json
import re
from html.parser import HTMLParser
class Visible(HTMLParser):
def __init__(self):
super().__init__()
self.skip = False
self.text = []
def handle_starttag(self, tag, attrs):
if tag in ("script", "style"):
self.skip = True
def handle_endtag(self, tag):
if tag in ("script", "style"):
self.skip = False
def handle_data(self, data):
if not self.skip:
self.text.append(data)
def check(html):
problems = []
visible = Visible()
visible.feed(html)
page_text = " ".join(" ".join(visible.text).split())
pattern = r'<script type="application/ld\+json">(.*?)</script>'
for raw in re.findall(pattern, html, re.S):
try:
data = json.loads(raw)
except json.JSONDecodeError as error:
problems.append(f"Invalid JSON: {error}")
continue
for item in data.get("mainEntity", []):
name = item.get("name", "")
if name and name not in page_text:
problems.append(f"Not visible on page: {name}")
return problems
html = """
<h2>What does a factory reset do?</h2>
<p>It erases all saved settings.</p>
<script type="application/ld+json">
{"@context": "https://schema.org", "@type": "FAQPage",
"mainEntity": [
{"@type": "Question", "name": "What does a factory reset do?"},
{"@type": "Question", "name": "How long does a reset take?"}
]}
</script>
"""
print(check(html))Running it prints ['Not visible on page: How long does a reset take?']. The second question exists only in the markup, so the script flags it.
This check is deliberately simple. It handles one block shape and looks only at question names. Official validators, such as the Schema Markup Validator and a search engine's rich results test, check vocabulary rules that this script does not. Use both kinds of tool.
Edge cases
- Multiple types on one page. An article that contains a how-to section can carry both an
Articleblock and aHowToblock. Use an array or separate script elements, and keep each one accurate. - Pages rendered by JavaScript. Some crawlers do not run scripts. Prefer putting the JSON-LD in the server-rendered HTML.
- Content that changes often. Prices and availability go stale fastest. Generate those fields from the same data source as the page, or leave them out.
- Long answers. In
acceptedAnswer, a short faithful summary of the visible answer is acceptable if it does not contradict the page. Simple HTML intextis allowed, but plain text is safer. - User-generated answers. For forum threads with answers from users,
QAPageis a better fit thanFAQPage, becauseFAQPageis for answers authored by the site.
Decision criteria
Ask these questions in order before adding a block.
- Is the visible structure already clean, with proper headings, lists, and tables? If not, fix that first.
- Does a schema.org type describe this page honestly?
- Can every value in the block be found on the page?
- Can you generate the block from the same source as the page, so it cannot drift?
- Is the maintenance cost acceptable? A block that nobody updates becomes a liability.
If the answer to any of these is no, skipping structured data is a reasonable choice. A page without it can still be retrieved and quoted if its content is clear.
Exercise
A product page shows the price "$40" in the visible text, but its Product JSON-LD contains "price": "35.00" because the price was changed last month. Name the problem, say what could go wrong, and give one way to prevent it.
Show answer
The structured data no longer mirrors the visible page. A system that reads both cannot tell which price is correct, so it may ignore the markup, show the wrong price, or the site may lose eligibility for enhanced results. To prevent it, generate both the visible price and the JSON-LD from the same data source, so a price change updates both. A validation check that compares the two values before publishing also catches drift.
Exercise
You add a FAQPage block to a page and the page ranks no better and is never cited in AI answers. Does that mean the markup is wrong? Explain.
Show answer
Not necessarily. Structured data is optional support and guarantees neither ranking nor citation. The markup can be valid and still have no visible effect, because retrieval systems weigh many signals and rely mainly on the visible text. Confirm the block parses, matches the visible content, and uses a fitting type, then judge the page on its content and structure.