Sub topic 8
Keeping Markup and Visible Text in Agreement
Assume you know basic HTML, JSON, and how a crawler reads a web page. You should also understand that JSON-LD is structured data embedded in a page. This chapter focuses on one rule: structured data must describe the same facts that a visitor can see.
Why agreement matters
Search engines and other systems may read both the visible page and its JSON-LD. They compare these sources to decide whether the page is trustworthy and eligible for enhanced search features.
For a product page, agreement includes:
| Fact | Visible page | Structured data |
|---|---|---|
| Product name | Heading and product details | `Product.name` |
| Price | Price label | `Offer.price` |
| Currency | Currency symbol or code | `Offer.priceCurrency` |
| Stock status | “In stock” or “Sold out” | `Offer.availability` |
| Product identity | SKU or variant details | `Product.sku` |
A mismatch can produce confusing search results. For example, a page might show €99 to visitors while its JSON-LD says €89. A crawler cannot know which price is reliable. It may ignore the markup, show an outdated price, or reduce trust in the page.
Render both views from one record
The safest design stores each fact in one authoritative product record. The page template uses that record to create both visible HTML and JSON-LD.
from decimal import Decimal
import json
product = {
"name": "Trail Runner 2",
"sku": "TR2-BLK-42",
"price": Decimal("89.00"),
"currency": "EUR",
"in_stock": True,
}
def availability_url(in_stock):
return "https://schema.org/InStock" if in_stock else "https://schema.org/OutOfStock"
def render_product(product):
price = f"{product['price']:.2f}"
stock_text = "In stock" if product["in_stock"] else "Sold out"
visible = (
f"<h1>{product['name']}</h1>"
f"<p>SKU: {product['sku']}</p>"
f"<p class='price'>{price} {product['currency']}</p>"
f"<p class='stock'>{stock_text}</p>"
)
structured = {
"@context": "https://schema.org",
"@type": "Product",
"name": product["name"],
"sku": product["sku"],
"offers": {
"@type": "Offer",
"price": price,
"priceCurrency": product["currency"],
"availability": availability_url(product["in_stock"]),
},
}
json_ld = json.dumps(structured, indent=2)
return visible, json_ld
visible_html, json_ld = render_product(product)
print(visible_html)
print(json_ld)This pattern prevents a content editor from changing the visible price while forgetting the structured data. In a real application, escape values before inserting them into HTML, and use the site’s normal currency and locale formatting rules.
Check the complete rendered page
Do not inspect only the template source. Test the final HTML after server-side rendering or client-side hydration. Check:
- The product named in JSON-LD is the product shown on the page.
- The price includes the same amount, currency, and active variant.
- Availability reflects the current inventory state.
- The URL identifies the same product or variant.
- Reviews, ratings, and shipping claims are present visibly if they appear in markup.
- Cached HTML, feeds, and APIs do not expose older values.
Use automated tests to compare the product record with the rendered values. Also run a structured-data validator and inspect representative pages manually after template changes.
Trace the fact to every output
When a price or stock state changes, update the record first. Then regenerate or invalidate every output that depends on it. This reduces drift between the page, search markup, merchant feeds, and cached responses.
Exercise
A product page visibly shows “Sold out,” but its JSON-LD contains https://schema.org/InStock. What should you change first?
Show answer
Correct the authoritative product record, then regenerate the visible page and JSON-LD from that record. Finally, clear or revalidate affected caches and test the rendered output.