In the fast‑moving world of SEO, a tiny mismatch between what your page says and what your structured data declares can cost you valuable traffic.
JSON‑LD validation against visible page text refers to the process of programmatically comparing the values in your JSON‑LD markup with the actual content shown to users on the same page.
Why Matching Matters for SEO
Search engines trust JSON‑LD as the authoritative source for rich results. When the markup diverges from the visible price, product name, or FAQ answer, Google may discard the snippet or downgrade the page’s ranking.
Keeping the two in sync prevents “data drift” and ensures that the rich results displayed in search truly reflect what users see.
How the Python Standard‑Library Script Works
The script uses only built‑in modules—json, re, urllib.request, and html.parser—to fetch a page, extract visible text, parse the embedded JSON‑LD, and compare key fields such as @type, name, price, and FAQ answer.
- Fetches the HTML with
urllib.request.urlopen. - Parses visible text using a tiny subclass of
HTMLParser. - Locates
<script type="application/ld+json">blocks and loads them withjson.loads. - Iterates over known schemas (Product, Offer, FAQPage) and flags any value that does not appear verbatim in the extracted page text.
The approach was demonstrated in an Oct 25 2026 blog post that achieved the comparison in about 90 lines of standard‑library Python (Oct 25 2026).
Step‑by‑Step Implementation Guide
- Download the script. Save the
check_jsonld.pyfile from the repository. - Run against a URL.
python check_jsonld.py https://example.com/product/123 - Review the output. The script prints a summary:
- Matched fields – everything looks good.
- Skipped fields – optional properties that are not required for rich results.
- Mismatched fields – exact text differences that need fixing.
- Integrate into CI. Add the script to your build pipeline so every deployment automatically validates JSON‑LD against the rendered page.
- Fix drift. Update either the template or the JSON‑LD block so the two sources agree, then re‑run the check.
Best Practices to Keep Structured Data in Sync
- Generate JSON‑LD from the same data source that renders the page content (e.g., a single API call).
- Include unit tests that assert
priceandnamevalues appear in both the HTML and the JSON‑LD. - Run the validation script as part of every pull request to catch drift early.
- Document which fields are mandatory for your target rich results and treat optional fields as “skip‑by‑default” in the script.
Frequently Asked Questions
Can the script handle microdata or RDFa?
No. It focuses exclusively on JSON‑LD because that format is the most widely adopted for Google rich results.
Do I need any third‑party libraries?
All required functionality is provided by Python’s standard library, so no external dependencies are needed.
What Python versions are supported?
The script was tested on Python 3.14.3, but it works on any 3.6+ release.
How does the script decide which fields to skip?
Fields that are optional in the schema.org definition or that lack a direct textual counterpart on the page are reported as “skipped” with an explanatory note.
Can I customize the list of schemas to check?
Yes. The script contains a dictionary mapping schema types to the properties you want to verify; you can extend it for custom types.
When you need a reliable partner to build or maintain such automation, Neptune Infotech’s seasoned developers can tailor solutions that keep your structured data accurate and your SEO performance strong.