research/json-ld-that-matches-the-page

Does Your Structured Data Say What Your Page Says? A JSON-LD Check for a Static Build

Engineering Note · November 13, 2026 · 8 minute read · Structured Data · AI Search · Node.js · Testing

You can catch structured data that has drifted away from its page with a short script that reads the built HTML, parses each JSON-LD block, and compares what the markup says with what a visitor can read. Ours is 74 lines of Node.js with no dependencies. On our own build it read 308 blocks across 218 pages and found nothing wrong. When we planted four kinds of mistake in a test folder, it reported every one and exited with status 1.

Everything below was run with Node.js 22.23.4 and Astro 7.3.8 on Linux. The outputs are the real ones from this run.

Why check the markup against the page?

JSON-LD is the block of structured data, in a <script type="application/ld+json"> tag, that states facts about a page in a form machines read directly: the business name, phone number, address, an article’s headline, a list of questions and answers. Google recommends JSON-LD over the other formats, and its general guidelines set two rules this check is built around: “Don’t mark up content that is not visible to readers of the page,” and “Your structured data must be a true representation of the page content.”

Markup drifts because it is usually written in a different place from the page. A template fills in the phone number from one setting while a footer hard-codes another. Someone edits a FAQ answer in the page copy and forgets the markup. The page still looks right, so nobody notices.

Google also says there is no special markup needed for its AI features, and FAQ rich results stopped appearing in Google Search on May 7, 2026. So the reason to keep structured data honest is simpler than chasing a feature: answer engines read pages and repeat facts, and a fact stated two different ways on your own site is a fact they may get wrong.

What does the check test?

Four things, each a common way markup goes wrong:

  1. Every block parses. A trailing comma makes the whole block invalid, and a parser that fails silently ignores it.
  2. FAQ text is on the page. Every question and every answer in a FAQPage block must appear in the page’s visible text.
  3. Article headlines match the page. An Article or TechArticle headline must equal the page’s <h1>, ignoring case and spacing.
  4. One business, one phone number and address. For each business name marked up with a phone number or address, every page must give the same ones.

Visible text here means the HTML with scripts, styles and tags removed, entities decoded, curly quotes straightened, whitespace collapsed and everything lower-cased. Comparisons are on that normalized text.

What does the code look like?

// Audit JSON-LD in a static build: does the markup say what the page says?
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative } from 'node:path';

const root = process.argv[2];
const files = [];
(function walk(d) {
  for (const n of readdirSync(d)) {
    const p = join(d, n);
    if (statSync(p).isDirectory()) walk(p); else if (p.endsWith('.html')) files.push(p);
  }
})(root);

const decode = s => s
  .replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(+n))
  .replace(/&#x([0-9a-f]+);/gi, (_, n) => String.fromCodePoint(parseInt(n, 16)))
  .replace(/&nbsp;/g, ' ').replace(/&quot;/g, '"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
const norm = s => decode(s).replace(/[‘’]/g, "'").replace(/[“”]/g, '"').replace(/\s+/g, ' ').trim().toLowerCase();
const visibleText = html => norm(html
  .replace(/<script[\s\S]*?<\/script>/gi, ' ').replace(/<style[\s\S]*?<\/style>/gi, ' ')
  .replace(/<[^>]+>/g, ' '));

const problems = [];
const nap = new Map(); // business name -> Map("telephone | street" -> page count)
let blocks = 0, faqPairs = 0, headlines = 0;

for (const f of files) {
  const page = '/' + relative(root, f);
  const html = readFileSync(f, 'utf8');
  const text = visibleText(html);
  const h1 = (html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i) || [])[1];
  for (const m of html.matchAll(/<script[^>]*type="application\/ld\+json"[^>]*>([\s\S]*?)<\/script>/gi)) {
    blocks++;
    let data;
    try { data = JSON.parse(m[1]); } catch (e) { problems.push([page, 'invalid JSON: ' + e.message]); continue; }
    const items = Array.isArray(data) ? data : data['@graph'] ?? [data];
    for (const it of items) {
      const type = [].concat(it['@type']);
      if (!data['@context'] && !it['@context']) problems.push([page, `${type} has no @context`]);
      if (type.includes('FAQPage')) {
        for (const q of it.mainEntity ?? []) {
          faqPairs++;
          if (!text.includes(norm(q.name ?? ''))) problems.push([page, `FAQ question not on page: "${q.name}"`]);
          const a = q.acceptedAnswer?.text ?? '';
          if (!text.includes(norm(a))) problems.push([page, `FAQ answer not on page: "${a.slice(0, 60)}…"`]);
        }
      }
      if ((type.includes('Article') || type.includes('TechArticle')) && h1 !== undefined) {
        headlines++;
        if (norm(it.headline ?? '') !== visibleText(h1)) problems.push([page, `headline "${it.headline}" differs from <h1> "${visibleText(h1)}"`]);
      }
      if (it.telephone || it.address) {
        const variants = nap.get(it.name) ?? new Map();
        const key = [it.telephone, it.address?.streetAddress].join(' | ');
        variants.set(key, (variants.get(key) ?? 0) + 1);
        nap.set(it.name, variants);
      }
    }
  }
}

console.log(`${files.length} pages, ${blocks} JSON-LD blocks, ${faqPairs} FAQ pairs, ${headlines} headlines`);
console.log(`${problems.length} problems`);
for (const [page, msg] of problems.slice(0, 15)) console.log(`  ${page}: ${msg}`);
if (problems.length > 15) console.log(`  … and ${problems.length - 15} more`);
let mismatched = 0;
for (const [name, variants] of nap) {
  if (variants.size < 2) continue;
  mismatched++;
  console.log(`  "${name}" has ${variants.size} phone/address variants:`);
  for (const [k, n] of variants) console.log(`    ${n} pages: ${k}`);
}
console.log(`${nap.size} businesses marked up, ${mismatched} with inconsistent phone or address`);
process.exitCode = problems.length || mismatched ? 1 : 0;

The business check groups by the marked-up name. Our build includes demonstration sites for made-up businesses, each with its own name, so they count as separate businesses rather than as conflicting phone numbers for one.

What did it find on our own build?

We built the site with SHOW_SCHEDULED=1 npx astro build, which includes posts scheduled for later dates, and ran the check on the output folder:

$ node check-jsonld.mjs dist
218 pages, 308 JSON-LD blocks, 333 FAQ pairs, 63 headlines
0 problems
15 businesses marked up, 0 with inconsistent phone or address
$ echo $?
0

It checked every FAQ question and answer and every article headline on the site and found no mismatches. The 15 businesses are GVX Digital, marked up on most pages with one phone number and address, and the made-up businesses on our template demonstration pages. A second timed run took 147 ms.

Does it catch problems when they exist?

A clean result only means something if the check can fail. We made a test folder with three pages for a fictional plumber, each with one planted mistake:

  • services.html marks up a weekend-hours answer (“Saturday and Sunday from 8 AM to 4 PM”) while the page says “Saturday from 8 AM to noon.”
  • contact.html gives a different phone number from services.html, and has an Article block with a trailing comma.
  • guide.html has a headline that was shortened after the page title changed.
$ node check-jsonld.mjs fixture
3 pages, 5 JSON-LD blocks, 2 FAQ pairs, 1 headlines
3 problems
  /contact.html: invalid JSON: Expected double-quoted property name in JSON at position 57 (line 1 column 58)
  /guide.html: headline "How to Winterize Outdoor Faucets" differs from <h1> "how to winterize outdoor faucets in kentucky"
  /services.html: FAQ answer not on page: "Yes, Saturday and Sunday from 8 AM to 4 PM.…"
  "Example Plumbing" has 2 phone/address variants:
    1 pages: (502) 555-0199 | 100 Main St
    1 pages: (502) 555-0100 | 100 Main St
1 businesses marked up, 1 with inconsistent phone or address
$ echo $?
1

All four mistakes were reported: the invalid block, the stale answer, the headline and the second phone number. The unchanged question about estimates passed.

How would we use it?

The check reads a build folder and exits with status 1 on any problem, so it fits as a step after the build in a deploy pipeline, the same way as our internal link checker. A failed run stops the deploy before wrong facts go live.

When adapting it, two choices matter:

  • What counts as a business. Grouping by name suits a site with one business. A site with several locations under one name should group by @id or by name plus street address instead.
  • How strict to be about text. Exact matching after normalization catches stale answers. It also fails on harmless rewording. We prefer that strictness, because the fix (copy the page text into the markup, or generate both from one source) is quick.

The better long-term fix is to generate the markup and the page from the same data. On our site, research posts build their FAQ markup from the same front matter that renders the visible questions, so the two cannot drift apart.

Sources

Limitations

  • It does not validate against the schema.org vocabulary or any search engine’s rich result requirements. Use a validator for property names, types and required fields.
  • Text hidden with CSS, or inside a collapsed element, still counts as visible. The check can’t tell what a browser shows.
  • Only @graph, arrays and single top-level objects are read. Nested entities, such as an Organization inside an Article’s publisher, are not checked for consistency.
  • The headline check uses the first <h1> on the page. A page with no <h1> is skipped.
  • Regular expressions are enough for HTML that our own build produces. They are not a general HTML parser.

Frequently asked questions

Why does it matter if JSON-LD doesn't match the visible page?

Google's structured data guidelines say not to mark up content that readers can't see and that markup must be a true representation of the page. Search and AI systems can also repeat what the markup says. A FAQ answer or phone number that changed on the page but not in the markup can be quoted back to customers wrong.

How do I test structured data on every page of a static site?

Run a script over the built HTML. Pull out each script tag of type application/ld+json, parse it, and compare its text fields with the page's visible text. Our version checked 308 blocks across 218 pages in about 0.15 seconds and exits with status 1 when it finds a problem, so it can stop a deploy.

Do I need special schema markup to appear in AI Overviews or ChatGPT?

Google says there is no special schema.org markup needed for its AI features. Structured data is still a clear, machine-readable statement of facts like your name, address and phone number, so the value is in it being correct and consistent, which is what this check tests.

Is FAQPage markup still worth adding?

Google stopped showing FAQ rich results in Search on May 7, 2026, so the expandable result is gone. Questions and answers on the page can still help readers. If you keep FAQPage markup, make sure every question and answer in it also appears on the page, which this check verifies.

What does this check not catch?

It does not validate against the schema.org vocabulary or any search engine's rich result rules, and it counts text as visible even when CSS hides it. It also compares by exact normalized text, so a reworded answer fails even when the meaning is the same. Pair it with a validator for the rest.

More from Research

← All research