Sub topic 6
Expressing facts in JSON-LD
This chapter assumes you can read and write JSON, know basic HTML, and have edited a content or e-commerce site. It covers how to state facts such as dates, prices, and availability in a form that search engines and AI answer systems can read without guessing. Later chapters apply the same ideas to products and offers in detail.
What JSON-LD is and why it helps
JSON-LD (JavaScript Object Notation for Linked Data) is a way to describe a page's facts as a block of JSON. It uses shared vocabulary from schema.org, so a crawler knows that price means a price and datePublished means a publication date. The block sits in the page inside a script tag with the type application/ld+json. Visitors do not see it. Crawlers read it directly.
Without markup, a crawler has to infer facts from layout and wording. A page that says "Updated 3 days ago" or "From 89" leaves room for error. Structured data removes some of that guesswork by giving each fact a name, a type, and a machine-readable value.
Markup does not replace visible text. It is a second statement of the same facts. If the two statements disagree, you have created a trust problem, not solved one. The chapter on keeping markup and visible text in agreement covers that in depth. Here the focus is on how to write the markup correctly.
The anatomy of a JSON-LD block
Every block has three kinds of keys:
@contextsays which vocabulary the keys come from. For schema.org it ishttps://schema.org.@typesays what kind of thing the block describes, such asArticleorProduct.- Property keys such as
headlineordatePublishedhold the facts.
Here is a block for an article, with the original publication date and the last meaningful modification stated separately.
{
"@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"
}Here is how to embed it in a page:
<script type="application/ld+json">
{
"@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"
}
</script>The block can go in the head or the body. Pick one place and use it on every template, so audits are simple.
Writing dates correctly
Dates are the most common source of subtle markup errors. Follow these rules.
- Use ISO 8601 format. A full timestamp looks like
2026-11-20T08:00:00+00:00. A date alone,2026-11-20, is also valid. - Include a time zone offset when you include a time. Without one, consumers may read the time in different zones, and the date can shift by a day.
- Keep
datePublishedfixed once the page is live. It records when the content first appeared. - Set
dateModifiedto the time of the last meaningful change, not the time of the last deployment or cache rebuild. - Never let
dateModifiedbe earlier thandatePublished. Validators and crawlers treat that as an error.
The visible page should show the same dates, for example "Published 2 March 2026, updated 20 November 2026". The earlier chapters on published and modified dates explain what counts as a meaningful change. The markup simply reports that decision.
Prices and offers
A product page states its commercial facts through an Offer nested inside a Product. Nesting matters. The offer belongs to the product, so it is a property whose value is another object with its own @type.
{
"@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"
}
}Points that cause trouble in practice:
priceis a plain number as a string, with a period as the decimal separator and no currency symbol or thousands separator. Write"89.00", not"€89,00".priceCurrencyis a separate property using a three-letter ISO 4217 code such asEURorUSD.availabilityis a full schema.org URL, for examplehttps://schema.org/InStockorhttps://schema.org/OutOfStock. A bare word like"in stock"is not a valid value.priceValidUntilstates when the price stops being guaranteed. If you include it, it must be a real date you will honour or update, not a far-future placeholder.skuidentifies the specific variant. If the page sells several variants at different prices, describe each one or describe the page's default variant accurately.
Generating markup from one source
Hand-written JSON-LD drifts. Someone changes the price in the template and forgets the script block. The fix is to build both the visible label and the markup from the same product record, so neither can differ from the other.
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))Running this prints 89.00 EUR followed by the JSON-LD block. Three details are worth noting:
- The price is a
Decimal, not a float. Floats can produce values like89.00000000001, andstr()of aDecimalkeeps the exact digits you stored. json.dumpshandles escaping. If a product name contains a quote or a</script>sequence, string concatenation could break the page or open an injection hole. Always serialise with a JSON library. When you embed the output in HTML, also escape any<as\u003cso the text can never close the script tag early.price_labelandproduct_jsonldread the same dictionary. This is the single-source-of-truth idea from the earlier chapter, applied to markup.
How the pieces connect
The diagram shows the flow from one record to every place a fact appears.
Common errors
| Problem | What goes wrong | Fix |
|---|---|---|
| Price with currency symbol in `price` | Parsers read the value as invalid or ignore it | Put digits only in `price`, the code in `priceCurrency` |
| Date without time zone | The date can be read as the day before or after | Add an offset such as `+00:00` |
| `dateModified` set on every deploy | Dates stop reflecting real changes and lose credibility | Update only on meaningful content changes |
| Markup says `InStock`, page says "sold out" | Search systems see a contradiction and may drop the rich result | Generate both from one record |
| Markup for content not on the page | Treated as misleading structured data and can lead to a manual action | Only mark up facts a visitor can see |
| Invalid JSON, such as a trailing comma | The whole block is ignored | Serialise with a library and validate |
| Multiple conflicting blocks on one page | Crawlers cannot tell which one is true | Emit one block per entity |
Testing your markup
Check the markup in three ways.
- Parse it. Extract the script contents and load them with a JSON parser in a test. Failure here means a syntax error.
- Compare it with the page. In a test, fetch the rendered HTML, read the visible price and the
pricein the JSON-LD, and assert they match. - Validate it with an external tool. Google's Rich Results Test and the Schema Markup Validator report missing or invalid properties and show how a crawler reads the page.
Run these checks against the rendered output, not just your source templates. Caches, plugins, and tag managers can change what actually gets served. A later chapter on automated checks builds this into a routine.
Exercise
A product page shows "Price: 79.00 USD" and its JSON-LD contains "price": "$79", "priceCurrency": "USD", and "availability": "in stock". Name the problems and write the corrected Offer fields.
Show answer
There are two problems. The price value includes a currency symbol, and the availability is not a schema.org URL. Corrected fields: "price": "79.00", "priceCurrency": "USD", "availability": "https://schema.org/InStock". Ideally the page generates both the label and the markup from one product record so they cannot differ.
Exercise
An article was first published on 5 May 2026 and had a typo fixed on 1 September 2026. Its JSON-LD sets dateModified to 1 September 2026. Is that correct? What would you do differently if the update had been a rewritten pricing section?
Show answer
Probably not. A typo fix is not a meaningful change, so dateModified should stay at the last meaningful update, and datePublished stays 2026-05-05. A rewritten pricing section changes facts readers rely on, so dateModified should be set to the time of that change, with the visible "updated" date changed to match.