Sub topic 7
Marking up prices, availability, and product details
This chapter assumes you know basic HTML, JSON, and how a server delivers a web page. You should also understand that crawlers read both visible page content and structured data.
Product markup describes an offer
Schema.org is a vocabulary for describing entities such as products, prices, and sellers. JSON-LD is a format for placing that description in a page without mixing it into the visible text.
A product usually contains stable identity fields, such as its name and SKU. An Offer describes a sellable version of that product. The offer can include its price, currency, stock status, URL, and price validity period.
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Trail Runner 2",
"sku": "TR2-BLK-42",
"brand": {
"@type": "Brand",
"name": "Example Athletics"
},
"offers": {
"@type": "Offer",
"url": "https://example.com/p/trail-runner-2",
"price": "89.00",
"priceCurrency": "EUR",
"availability": "https://schema.org/InStock",
"priceValidUntil": "2026-12-31"
}
}Use an ISO 4217 currency code, such as EUR, USD, or GBP. Represent the price precisely. A price of 89 euros should not become 89.99 in the markup while the page displays 89.00.
priceValidUntil is useful when the date is real and maintained. Do not set a date far in the future merely to satisfy a validation tool. An expired validity date can make the offer appear unreliable.
Keep visible content and markup consistent
Search engines compare structured data with the page that users see. The product name, price, currency, stock status, and important conditions should agree across both representations.
| Fact | Visible page | Structured data |
|---|---|---|
| Price | `89.00 EUR` | `"price": "89.00"` and `"priceCurrency": "EUR"` |
| Stock | `In stock` | `https://schema.org/InStock` |
| Product identity | `Trail Runner 2` | `"name": "Trail Runner 2"` |
Do not mark an item as InStock when the page says “sold out.” Do not expose a discounted structured-data price if the discount is visible only after a user selects a membership, size, or promotional code. Describe the offer that an ordinary user can actually obtain, or model the variants and conditions explicitly.
Generate markup from the product record
A single source of truth prevents hand-edited values from drifting. The page renderer, JSON-LD generator, and merchant feed should all read the same current product record.
import json
product = {
"name": "Trail Runner 2",
"sku": "TR2-BLK-42",
"price": "89.00",
"currency": "EUR",
"in_stock": True,
}
availability = (
"https://schema.org/InStock"
if product["in_stock"]
else "https://schema.org/OutOfStock"
)
markup = {
"@context": "https://schema.org",
"@type": "Product",
"name": product["name"],
"sku": product["sku"],
"offers": {
"@type": "Offer",
"price": product["price"],
"priceCurrency": product["currency"],
"availability": availability,
},
}
print(json.dumps(markup, indent=2))Validate generated JSON-LD in automated tests. Check required fields, valid currency codes, nonnegative prices, recognized availability values, and agreement with the rendered page. Also test each important product variant when size, color, or regional pricing changes the offer.
Exercise
The page displays “Out of stock” and 89.00 EUR, but its JSON-LD says InStock and 79.00 USD. What should you change first?
Show answer
Fix the generation path so the visible page and JSON-LD read the same authoritative product record, then validate the corrected output.