DEV Community

Peter Panda
Peter Panda

Posted on

Validating JSON-LD Consistency Across Language Versions With a Script

Multilingual sites often have structured data that drifts between languages. The English page lists a phone number, the Japanese page has an old one, the Chinese page is missing the address entirely. Search engines and AI assistants read these as conflicting facts about the same organisation. A short script can catch the drift before it spreads.

What to compare

Some fields should be identical across languages:

  • Organisation name (or a deliberate, documented localised name)
  • url, logo, telephone, email
  • address components
  • sameAs profile links

Other fields are expected to differ, such as description. The script should compare the first group and ignore the second.

Extracting JSON-LD

import json, re, requests

def jsonld(url):
    html = requests.get(url, timeout=20, headers={"User-Agent": "schema-check"}).text
    blocks = re.findall(r'<script[^>]+application/ld\+json[^>]*>(.*?)</script>', html, re.S)
    out = []
    for b in blocks:
        try:
            data = json.loads(b)
        except json.JSONDecodeError:
            print("invalid JSON-LD on", url)
            continue
        out.extend(data if isinstance(data, list) else [data])
    return out

def org(items):
    for it in items:
        if it.get("@type") in ("Organization", "LocalBusiness", "ProfessionalService"):
            return it
    return {}
Enter fullscreen mode Exit fullscreen mode

Comparing versions

FIELDS = ["url", "logo", "telephone", "email", "sameAs"]
pages = {
    "en": "https://example.com/en/about/",
    "zh": "https://example.com/zh/about/",
    "ja": "https://example.com/ja/about/",
}
ref = org(jsonld(pages["en"]))
for lang, url in pages.items():
    o = org(jsonld(url))
    for f in FIELDS:
        a, b = ref.get(f), o.get(f)
        if isinstance(a, list): a, b = sorted(a), sorted(b or [])
        if a != b:
            print(f"[{lang}] {f}: {b!r} != en {a!r}")
Enter fullscreen mode Exit fullscreen mode

Run it in CI after each deploy, or weekly from a cron job.

Common findings

  • Phone formats. One version uses +852 ..., another uses local format without the country code. Pick international format everywhere.
  • Stale sameAs links. A social profile that was renamed on one language version only.
  • Missing blocks. Translated templates that dropped the script tag entirely.
  • Invalid JSON. Translators editing a template and breaking a quote or comma.

Why it matters for AI search

Assistants build an internal picture of who a company is from many sources. Your own site should be the most consistent of them. If it disagrees with itself across languages, it is harder for a model to state your details with confidence.

For the rest of the multilingual checklist, including hreflang and URL structure, see our multilingual SEO guide.

Published by PandaWM, an overseas marketing team based in Hong Kong.

Top comments (0)