Sub topic 8
Keeping markup and visible text in agreement
This chapter assumes you can read HTML and JSON, know what schema.org JSON-LD looks like, and have seen a Product with an Offer. It covers how to keep the structured data and the text a visitor reads saying the same thing, and how to find the places where they drift apart.
Why the two copies must agree
A product page usually carries its facts twice. People read the price in the HTML. Crawlers and AI answer systems also read it from the JSON-LD block. If the two disagree, a system that reads both has to pick one, or it may distrust the page.
Search engines state this as a rule. Google's structured data guidelines say markup must describe content that is visible to the reader on the page. A page that marks up a price the visitor never sees can lose rich results. In serious cases it can receive a manual action for misleading markup.
Most mismatches are accidents, not deception. Someone edits the visible price and forgets the markup. A template hard-codes InStock while the visible text says "Sold out". A cache serves the old HTML with the new JSON-LD. The causes differ, but the result is the same: two statements about one fact.
Where drift comes from
Knowing the common sources helps you decide what to check.
| Source of drift | Example | Typical fix |
|---|---|---|
| Hand-edited markup | Editor changes the price in the page body but not in a JSON-LD field | Generate markup from the product record |
| Hard-coded template values | `"availability": "InStock"` is written into the template | Compute it from stock data |
| Different data paths | The visible price comes from the database, the markup from a feed export | Make both read the same record |
| Client-side rendering | JavaScript updates the visible price after load, the server-rendered JSON-LD stays old | Render both on the server, or update both in one function |
| Caching | HTML is cached for an hour, the JSON-LD is injected by a tag manager with fresh data | Cache the whole document as one unit |
| Formatting differences | Visible "89,00 €" versus markup `"89.00"` | Compare normalised values, not strings |
| Variant confusion | Page shows the black size 42, markup describes the default variant | Mark up the variant that is selected |
The first three rows share one cure, covered in the earlier chapter on a single source of truth: store each fact once and render every copy from it.
Render both copies from one record
The simplest way to keep two copies in agreement is to never write the second copy by hand. The code below builds the visible label and the JSON-LD from the same product dictionary. It uses Decimal so that 89.00 stays 89.00 and is not turned into a float.
from decimal import Decimal
import json
def product_jsonld(p):
availability = 'https://schema.org/InStock' if p['in_stock'] else 'https://schema.org/OutOfStock'
return {
'@context': 'https://schema.org',
'@type': 'Product',
'name': p['name'],
'sku': p['sku'],
'offers': {
'@type': 'Offer',
'price': str(p['price']),
'priceCurrency': p['currency'],
'availability': availability,
},
}
def price_label(p):
return ' '.join([str(p['price']), p['currency']])
product = {'name': 'Trail Runner 2', 'sku': 'TR2-BLK-42', 'price': Decimal('89.00'), 'currency': 'EUR', 'in_stock': True}
print(price_label(product))
print(json.dumps(product_jsonld(product), indent=2))Both functions read p['price'] and p['currency']. A change to the record changes both outputs on the next render. There is no second place to forget.
Three details matter here:
- The markup price is a plain number string such as
89.00. Do not put the currency symbol or thousands separators in it. The currency goes inpriceCurrency. - The visible label is for people and can use local formatting. The markup is for machines and must stay in the schema.org format.
- Availability is computed from
in_stock. No template contains a fixed value.
Here is the page the output above would produce, with the matching Offer:
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Trail Runner 2",
"sku": "TR2-BLK-42",
"offers": {
"@type": "Offer",
"url": "https://example.com/p/trail-runner-2",
"price": "89.00",
"priceCurrency": "EUR",
"priceValidUntil": "2026-12-31",
"availability": "https://schema.org/InStock"
}
}Note priceValidUntil. It is a date after which the stated price should no longer be trusted. If you include it, it becomes a fact with its own decay. A date that has already passed makes an otherwise correct Offer look expired. Either keep it updated from the same record or leave it out.
Dates need the same treatment
The rule applies to dates too. If the page shows "Updated 20 November 2026", the markup should carry a matching dateModified:
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to choose trail running shoes",
"datePublished": "2026-03-02T09:00:00+00:00",
"dateModified": "2026-11-20T08:00:00+00:00"
}The visible date and dateModified should come from one stored timestamp. Show the date in the reader's format, and write the ISO 8601 form in the markup. Two cases cause trouble:
- A visible "Updated today" label that is computed at render time, next to a fixed
dateModified. The page then claims to be updated daily when it is not. - A
dateModifiedthat a plugin bumps on every save, while the visible date shows the last editorial change. This is the date gaming covered earlier in the tutorial, and it also produces a mismatch.
What to compare
A consistency check needs a list of fields and a rule for each one. The most important fields are these:
- Price. Compare as decimals after stripping symbols and separators.
89,00 €and89.00are equal.89.00and79.00are not. - Currency. Compare the ISO 4217 code (
EUR) with the symbol or code shown on the page. - Availability. Map visible phrases to schema.org values. "In stock" and "Ships today" map to
InStock. "Sold out" maps toOutOfStock. "Pre-order" maps toPreOrder. - Name and SKU. The product name and identifier in the markup should appear on the page.
- Modified date. Compare the calendar day. A difference in time zone offset can move the day, so normalise to one zone first.
Not every mismatch is a bug. A page can show a struck-through list price and a sale price. The markup should describe the price the buyer pays now, not the crossed-out one. Your rules need to say which visible number counts.
Automated check
You can catch most drift with a script that fetches the page, reads the JSON-LD, extracts the visible price, and compares them. This example uses only the standard library plus requests for fetching, and parses a saved page so it runs offline.
import json
import re
from decimal import Decimal, InvalidOperation
PAGE = '''
<html><body>
<h1>Trail Runner 2</h1>
<p class="price">89,00 EUR</p>
<script type="application/ld+json">
{"@context": "https://schema.org", "@type": "Product", "name": "Trail Runner 2",
"offers": {"@type": "Offer", "price": "79.00", "priceCurrency": "EUR",
"availability": "https://schema.org/InStock"}}
</script>
</body></html>
'''
def jsonld_blocks(html):
pattern = r'<script type="application/ld\+json">(.*?)</script>'
return [json.loads(m) for m in re.findall(pattern, html, re.S)]
def visible_price(html):
m = re.search(r'<p class="price">\s*([\d.,]+)\s*([A-Z]{3})', html)
if not m:
return None
number = m.group(1).replace(',', '.')
try:
return Decimal(number), m.group(2)
except InvalidOperation:
return None
def check(html):
problems = []
visible = visible_price(html)
for block in jsonld_blocks(html):
if block.get('@type') != 'Product':
continue
offer = block['offers']
marked = (Decimal(offer['price']), offer['priceCurrency'])
if visible != marked:
problems.append(f'visible {visible} but markup {marked}')
return problems
print(check(PAGE) or 'ok')Running it prints visible (Decimal('89.00'), 'EUR') but markup (Decimal('79.00'), 'EUR'), inside a list. The visible price is 89 and the markup says 79, so the check reports the page.
This script is a sketch. It treats a comma as a decimal point, so it would misread 1,299.00. A real checker needs a locale-aware parser and should use an HTML parser instead of regular expressions. It also needs to run against the rendered page, after JavaScript has executed, if your site changes prices on the client.
Where to run the check
Run the check in more than one place, because each place catches a different failure.
- At build or render time. A unit test on the template asserts that the visible price and the markup price come out equal for sample products. This catches code mistakes.
- After deployment. A scheduled job fetches a sample of live product URLs. This catches cache and CDN problems that a unit test cannot see.
- After a price change. A hook on the price update fetches that product's page after the cache purge and compares. This catches stale cache entries within minutes.
The diagram shows how one record feeds every output, and where a check sits.
Edge cases
- Price ranges. A page with several variants at different prices should use
AggregateOfferwithlowPriceandhighPrice, or mark each variant separately. A singlepriceequal to the cheapest variant misleads if the visible text says "from 89 EUR" without saying so. - Currency by region. If the page shows prices in the visitor's currency, the server must serve markup in that currency too. A crawler that fetches from one country sees one version. Give each regional version its own URL so the crawler can find each one.
- Tax. If the visible price includes VAT, the markup price should include it as well. Be consistent with what the buyer pays.
- Out of stock. Keep the page and set availability to
OutOfStockin both places. Do not remove the markup and leave the visible text unchanged. The next chapter section on retired products covers deleting or redirecting pages. - Multiple blocks. Plugins sometimes add a second Product block. Two blocks with different prices are a mismatch even when one is correct. Make the checker look at all of them.
Common errors
- Fixing the markup by hand after an incident. It drifts again at the next edit. Fix the generator.
- Comparing strings.
"89.00"and"89,00 EUR"are different strings but the same price. - Testing only the origin server. The cache is where most real mismatches appear.
- Marking up a price the visitor cannot see, such as a trade price shown only after login.
- Leaving
priceValidUntilin the past.
Exercise
A product page shows "Sold out" in the visible text, but the JSON-LD still says "availability": "https://schema.org/InStock". The template contains the literal InStock string. Name two changes you would make, and say where you would run a check that would have caught this.
Show answer
First, remove the literal and compute availability from the stock field of the product record, so the visible label and the markup both depend on the same value. Second, add a template unit test that renders a product with in_stock set to false and asserts that the markup contains OutOfStock and the visible text says "Sold out". Run the check at build time to catch the code mistake. Also run a scheduled fetch of live product URLs to catch the same mismatch if a cache serves an old copy.
Exercise
Your checker reports the visible price 1.299,00 EUR and the markup price 1299.00 as different. What is the likely cause, and how do you fix the checker?
Show answer
The checker is comparing strings, or it is parsing the visible number with the wrong separators. In this locale the dot groups thousands and the comma is the decimal point. Parse the visible price with a locale-aware parser, strip grouping separators, convert to Decimal, and compare Decimal values and currency codes. Add a test case for each locale you serve.