Structured data breaks quietly. A theme update changes a template, a plugin outputs a second Organization block, someone pastes a trailing comma into a custom field, and the page still looks perfect. You find out weeks later, if at all, when a rich result disappears.

The fix is boring and effective: treat JSON-LD like code and check it automatically. This post shows a small script that fetches pages, extracts every JSON-LD block, and fails loudly when something is off. No dependencies beyond Python's standard library.

What can go wrong

From small business sites I have looked after, the problems fall into a handful of groups:

  • Invalid JSON. A stray comma or an unescaped quote in a business description. The whole block is ignored.
  • Duplicates. Two plugins both emit LocalBusiness or Organization, with slightly different names or addresses.
  • Missing basics. No name, url or address where the type expects them.
  • Relative or http URLs. url fields that point at staging, or at the http version of the site.
  • Stale data. Opening hours or a phone number that no longer match the footer.

None of these need a paid tool to catch. They need a loop and a few assertions.

The script

import json, re, sys from urllib.request import Request, urlopen PAT = re.compile( r'<script[^>]+type=["\']application/ld\+json["\'][^>]*>(.*?)</script>', re.S | re.I, ) def blocks(url): req = Request(url, headers={"User-Agent": "schema-check/1.0"}) html = urlopen(req, timeout=20).read().decode("utf-8", "replace") return PAT.findall(html) def flatten(node): if isinstance(node, list): for n in node: yield from flatten(n) elif isinstance(node, dict): if "@graph" in node: yield from flatten(node["@graph"]) else: yield node def check(url): problems, types = [], [] for raw in blocks(url): try: data = json.loads(raw) except json.JSONDecodeError as e: problems.append(f"invalid JSON: {e}") continue for item in flatten(data): t = item.get("@type") t = t[0] if isinstance(t, list) else t types.append(t) u = item.get("url", "") if u and not u.startswith("https://"): problems.append(f"{t}: url is not absolute https: {u}") if t in ("LocalBusiness", "Organization") and not item.get("name"): problems.append(f"{t}: missing name") for t in set(types): if t in ("LocalBusiness", "Organization", "WebSite") and types.count(t) > 1: problems.append(f"duplicate {t} blocks ({types.count(t)})") return problems failed = False for u in sys.argv[1:]: for p in check(u): print(f"FAIL {u}: {p}") failed = True sys.exit(1 if failed else 0) 

Run it with a few URLs: the home page, one service page, one blog post and the contact page. Those four templates cover almost everything a typical WordPress theme outputs.

Where to run it

The script exits with code 1 on any problem, so it slots in anywhere a command can fail the job:

  1. After deploy, against the live URLs, as the last step in your deploy script.
  2. On a schedule, once a week from cron or a free CI runner, against a short list of key pages.
  3. After plugin or theme updates, by hand, before you tell the client the update is done.

Because it reads the rendered HTML, it catches output from plugins as well as from your own theme, which is where the duplicates come from.

Keep the content honest

Validation of syntax is the easy half. The other half is checking that the data is true. Compare the schema's name, address and phone with what the footer and contact page say. Google's local business structured data guide lists the properties it reads, and the vocabulary itself is on schema.org. Only mark up what a visitor can see on the page, and never add review or rating markup for reviews that are not shown.

A cheap way to catch drift is to add a few lines that compare the JSON-LD telephone to the first phone number found in the page body and warn when they differ.

What this will not do

It does not tell you whether Google will show a rich result, and it does not replace Google's own Rich Results Test for a new template. Use the script as a regression guard: once a template is right, make sure it stays right.

A checklist to keep

  • One Organization or LocalBusiness per page, not two.
  • Absolute https URLs everywhere.
  • Business details match the visible footer.
  • Valid JSON on every template, tested after each theme or plugin update.
  • A named person owns the check, so it does not rot.

If you want a second pair of eyes on markup as part of a wider technical review, our SEO services page shows what we cover. The script above is free to copy and adapt, so take it and change the assertions to match the sites you manage.