Sub topic 16
Keeping markup correct over time
This chapter assumes you can write JSON-LD with @context and @type, nest entities, embed markup in a script element, and run the validators. It covers what goes wrong after launch: markup that drifts away from the page, generated markup that breaks, and guideline violations that cost you rich results.
Why markup decays
Structured data is a second copy of facts that already appear on the page. Prices, dates, names, and availability are written once in the visible HTML and again in JSON-LD. Whenever the two copies are edited separately, they can disagree.
Search engines compare markup with the visible page. Markup that describes content users cannot see, or that contradicts it, is a guideline violation. Google can respond with a manual action, which removes your rich result eligibility for the affected pages. A mismatch is more than a cosmetic bug.
The usual causes of decay are:
- A price changes in the template but not in a hand-written JSON-LD block.
- A product goes out of stock and the page says so, but
availabilitystill saysInStock. - A redesign removes the author byline from the page, but the markup still names an author.
- A site moves to a new domain or URL scheme, and the
@idandurlvalues still point at the old one. - A CMS plugin and a theme both emit JSON-LD, so the page ends up with two conflicting
Articleentities.
Pitfall 1: markup that does not match visible content
Every fact you mark up should be visible to the user on the same page. This applies to both content and meaning.
- Do not mark up a review or rating that does not appear on the page.
- Do not add an
offersblock to a page that has no price or purchase option. - Do not mark up content that is hidden from users with CSS or only shown to crawlers.
- Do not describe a different page's content, such as putting the homepage's
Organizationdetails into every article as if they were the article's subject.
The following example shows a drifted Offer. The page shows "Sold out", but the markup was never updated.
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Stainless Steel Pour-Over Kettle",
"offers": {
"@type": "Offer",
"price": "39.90",
"priceCurrency": "EUR",
"availability": "https://schema.org/InStock"
}
}The fix is to change availability to https://schema.org/OutOfStock. The better fix is to stop editing the value by hand. Derive both the visible label and the markup from the same data field, as the generation section below shows.
Pitfall 2: syntax and type errors
Syntax errors are the most common failure in hand-written markup, and one error invalidates the whole block. The usual ones are:
- A trailing comma after the last property, or a missing comma between properties.
- Curly quotes pasted from a word processor in place of straight quotes.
- An unescaped double quote inside a string value.
- A raw line break inside a string. JSON requires
\n. - Comments. JSON does not allow them.
Type errors are subtler because the JSON is still valid. Check these:
| Mistake | Example | Fix |
|---|---|---|
| Wrong date format | `"datePublished": "14/03/2026"` | Use ISO 8601: `"2026-03-14T08:00:00+00:00"` |
| Currency symbol in the price | `"price": "€39.90"` | `"price": "39.90"` with `"priceCurrency": "EUR"` |
| Thousands separator in the price | `"price": "1,299.00"` | `"price": "1299.00"` |
| Enumeration as free text | `"availability": "in stock"` | `"https://schema.org/InStock"` |
| Relative URL | `"image": "/img/a.jpg"` | Use an absolute URL |
| Wrong type name | `"@type": "article"` | Type names are case-sensitive: `"Article"` |
| Wrong property name | `"datepublished"` | Property names are case-sensitive: `"datePublished"` |
A property name that schema.org does not define is silently ignored by consumers. The JSON stays valid, so only a vocabulary-aware validator such as the Schema Markup Validator reports it.
Pitfall 3: duplicated and conflicting entities
A page should describe each real-world entity once. Duplicates appear when several systems each emit their own markup.
Suppose an SEO plugin emits an Organization with "name": "Example Coffee Co.". The theme also emits one with "name": "Example Coffee". A consumer now sees two organizations and has no way to tell which is right.
Prevent this in three steps:
- Inventory every source of JSON-LD on a page. View the rendered HTML, not just your template, because plugins inject markup at render time.
- Pick one source of truth for each entity type and disable the others.
- Use stable
@idvalues, as in the@graphexample from earlier chapters. Two nodes with the same@iddescribe the same thing, so referencinghttps://example.com/#organizationfrom every page is safer than redefining the organization each time.
Stable @id values only help if they stay stable. An @id is an identifier, and it does not have to be a URL that resolves. Keep the pattern fixed across redesigns. If you change https://example.com/#organization to https://www.example.com/#org, every reference to the old value silently points at nothing.
Pitfall 4: required and recommended properties
Schema.org itself has almost no required properties. Any property valid for a type may be omitted. Google's rich result features, however, define their own requirements. A Product without offers, review, or aggregateRating can be valid schema.org and still be ineligible for a product rich result.
Treat the two as separate checks:
- The Schema Markup Validator answers: is this valid schema.org and valid JSON-LD?
- The Rich Results Test answers: does this meet the requirements of a Google feature?
Google's documentation lists required and recommended properties per feature, and it changes over time. Features have also been reduced or retired. For example, Google has limited which sites get FAQ and HowTo rich results. Markup that still validates may no longer produce a visible result. Do not treat a rich result as a guarantee. Treat it as something eligibility allows and that Google decides case by case.
Pitfall 5: unsafe generation
If your application builds JSON-LD from data, user-supplied values can break the output or cause an injection problem. A product name containing </script> closes the script element early. Everything after it is parsed as HTML.
Always build the markup from a data structure, serialize it with a JSON library, and escape </. Never build it by string concatenation.
import json
def render_json_ld(data: dict) -> str:
payload = json.dumps(data, ensure_ascii=False).replace("</", "<\\/")
return '<script type="application/ld+json">' + payload + "</script>"
def product_markup(name: str, price: str, currency: str, in_stock: bool) -> dict:
availability = "InStock" if in_stock else "OutOfStock"
return {
"@context": "https://schema.org",
"@type": "Product",
"name": name,
"offers": {
"@type": "Offer",
"price": price,
"priceCurrency": currency,
"availability": "https://schema.org/" + availability,
},
}
print(render_json_ld(product_markup("Kettle </script><b>", "39.90", "EUR", False)))The output contains <\/script> where the input had </script>. In JSON, \/ is a valid escape for /, so parsers read the original text back. The HTML parser never sees a closing tag.
Generation also keeps the markup in step with the page. In this example in_stock can drive both the visible label and the availability value. If one boolean feeds both, they cannot disagree.
Building a maintenance routine
Correct markup at launch is the start of the work. Put checks into the process so errors surface before users or search engines find them.
flowchart TDThe diagram below shows the loop to aim for.
Practical steps:
- Test in continuous integration. Parse every JSON-LD block from rendered pages for a sample of URLs, and fail the build on invalid JSON. Assert that key values, such as price, match the visible text.
- Validate templates, not just pages. One template can produce thousands of pages, so sample each template type.
- Monitor Search Console. The enhancement reports list errors and warnings per feature and per URL. Read them after each release.
- Review on redesign and migration. Check that URLs,
@idvalues, logos, and images still resolve. BrokenimageorlogoURLs are a common silent failure. - Keep dates honest. Update
dateModifiedwhen the content changes meaningfully, and not on every cosmetic edit. - Remove markup when the content goes away. If a product page is retired or an event has passed, update or remove the matching markup.
Quick reference
| Symptom | Likely cause | Check |
|---|---|---|
| Validator reports a parse error | Trailing comma, curly quotes, or raw line break | Run the block through a JSON parser |
| Rich result disappeared | Markup drifted from content, or the feature rules changed | Rich Results Test, then Google's current documentation |
| Two conflicting entities | Plugin and theme both emit markup | View rendered HTML and search for `ld+json` |
| Unknown property warning | Typo or wrong capitalization | Schema Markup Validator |
| References resolve to nothing | `@id` pattern changed | Compare `@id` values across pages |
Exercise
A product page shows "Sold out" and the price €39.90, but the JSON-LD still has "availability": "https://schema.org/InStock". The Schema Markup Validator reports no errors. Why does the validator pass, what is the actual problem, and what change to the application prevents it from recurring?
Show answer
The validator checks syntax and vocabulary, and "https://schema.org/InStock" is a valid enumeration value, so it passes. The problem is that the markup contradicts the visible content, which breaks structured data guidelines and can cost the page its rich results. To prevent a repeat, generate the visible label and the availability value from the same stock field in the application, so one boolean or status drives both. Add an automated test that compares the two.
Exercise
Why does the Python function above replace "</" with "<\/" after calling json.dumps, and why is the result still valid JSON?
Show answer
A value such as "</script>" would close the script element early, and the rest of the data would be parsed as HTML. Replacing "</" with "<\/" removes the closing-tag sequence from the HTML. In JSON, "\/" is a defined escape for "/", so a JSON parser reads the original text back unchanged.