GrepBoard/Manuals
605 manuals ·

Check AI-written Article JSON-LD with a script

·Tested on Claude Sonnet (sonnet alias) · Claude Code 2.1.302 · Python 3.12 · Ubuntu 24.04 · 2026-10 · Google Article docs (updated 2026-09-08)·Test scope ↓·9 steps

Parse AI-written Article JSON-LD, then check recommended properties, ISO 8601 dates and agreement with the page with a script, to catch values the AI made up.

JSON-LD can be valid syntax and still carry wrong values. An AI will fill in an author, image or modified time that the page never mentions. Build a script that checks in order: parse, properties, date format, match against the page. For the meta description counterpart, see Check AI-written meta descriptions for length and duplicates.

[1] Settle the criteria first. Google's Article structured data documentation (updated 2026-09-08) opens with:

The recommended properties are author (author.name, author.url), datePublished, dateModified, headline and image. Dates use ISO 8601, and the same page adds:

So the script below prints WARN for a missing property and FAIL for a wrong value. Passing the check does not guarantee a rich result. Structured data is information Google uses to understand a page; what it shows is Google's decision.

[2] Create the page to test. The post and company are made up. It has a <time datetime>, an author link and an og:image on purpose: these are what the JSON-LD gets compared with.

page.html
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Growing tomatoes on a winter balcony | Moonlight Farm Blog</title><link rel="canonical" href="https://example.com/blog/winter-balcony-tomato/"><meta property="og:image" content="https://example.com/img/winter-tomato-1200.jpg"></head><body><article><h1>Growing tomatoes on a winter balcony</h1><p class="byline">By <a rel="author" href="https://example.com/authors/a-kim/">A. Kim</a></p><p>Published <time datetime="2026-10-12T09:30:00+09:00">Oct 12, 2026</time> · Updated <time datetime="2026-10-25T14:05:00+09:00">Oct 25, 2026</time></p><p>Conditions for growing cherry tomatoes through a winter when the balcony drops below 10 °C.</p></article></body></html>

[3] Write the prompt and get the JSON-LD. The prompt pins the output to one JSON object and says not to make up values.

prompt.1.txt
Below is the HTML of one blog post. Write its schema.org Article JSON-LD.- Output a single JSON object only. No explanation, no code fences.- Use only information that is in the post; do not make up values.
console
$ cat prompt.1.txt page.html > in.1.txt$ claude -p --model sonnet --max-turns 1 < in.1.txt > out.1.json$ cat out.1.json{"@context":"https://schema.org","@type":"Article","headline":"Growing tomatoes on a winter balcony","description":"Conditions for growing cherry tomatoes through a winter when the balcony drops below 10 °C.","image":"https://example.com/img/winter-tomato-1200.jpg","author":{"@type":"Person","name":"A. Kim","url":"https://example.com/authors/a-kim/"},"datePublished":"2026-10-12T09:30:00+09:00","dateModified":"2026-10-25T14:05:00+09:00","mainEntityOfPage":{"@type":"WebPage","@id":"https://example.com/blog/winter-balcony-tomato/"},"inLanguage":"en"}

[4] Parse it with json.tool. A syntax error ends the check here.

console
$ python3 -m json.tool out.1.json > /dev/null && echo parsedparsed

[5] Write the checker. It uses only the Python standard library. It reads <h1>, <time datetime>, the rel="author" link and og:image from the page and compares them with the JSON-LD.

check_jsonld.py
#!/usr/bin/env python3"""usage: check_jsonld.py page.html jsonld.json — parse, recommended properties, ISO 8601, values vs page"""import sys, jsonfrom datetime import datetimefrom html.parser import HTMLParser class Page(HTMLParser):    def __init__(s):        super().__init__(); s.h1 = ""; s.h = s.a = False; s.times = []; s.authors = []; s.og = None    def handle_starttag(s, t, a):        a = dict(a); s.h = s.h or t == "h1"        if t == "time": s.times.append(a.get("datetime"))        if t == "a" and a.get("rel") == "author": s.a = True; s.authors.append(["", a.get("href")])        if t == "meta" and a.get("property") == "og:image": s.og = a.get("content")    def handle_endtag(s, t):        if t == "h1": s.h = False        if t == "a": s.a = False    def handle_data(s, d):        if s.h: s.h1 += d        if s.a: s.authors[-1][0] += d p = Page(); p.feed(open(sys.argv[1], encoding="utf-8").read())try:    j = json.load(open(sys.argv[2], encoding="utf-8"))except json.JSONDecodeError as e:    print("FAIL parse:", e); sys.exit(2)fail, warn = [], []if j.get("@type") not in ("Article", "NewsArticle", "BlogPosting"): fail.append(f"@type: {j.get('@type')!r}")warn += [f"missing {k}" for k in ("headline", "image", "author", "datePublished", "dateModified") if k not in j]if "headline" in j and j["headline"].strip() != p.h1.strip(): fail.append(f"headline differs from h1: {j['headline']!r} vs {p.h1.strip()!r}")for k in ("datePublished", "dateModified"):    if k not in j: continue    try: tz = datetime.fromisoformat(j[k]).tzinfo    except ValueError: fail.append(f"{k} not ISO 8601: {j[k]!r}"); continue    if tz is None: warn.append(f"{k} has no timezone: {j[k]!r}")    if j[k] not in p.times: fail.append(f"{k} {j[k]!r} not found in page <time>: {p.times}")for x in [j["author"]] if isinstance(j.get("author"), dict) else j.get("author", []):    if x.get("name") not in [n for n, _ in p.authors]: fail.append(f"author.name {x.get('name')!r} not in page byline: {[n for n, _ in p.authors]}")    if x.get("url") and x["url"] not in [u for _, u in p.authors]: fail.append(f"author.url {x['url']!r} not in page")for u in [j["image"]] if isinstance(j.get("image"), str) else j.get("image", []):    if u != p.og: fail.append(f"image {u!r} not the page's og:image {p.og!r}")for w in warn: print("WARN", w)for f in fail: print("FAIL", f)print(f"{len(fail)} fail, {len(warn)} warn"); sys.exit(1 if fail else 0)

[6] Check the first result.

console
$ python3 -I check_jsonld.py page.html out.1.json; echo "exit $?"0 fail, 0 warnexit 0

When the page has every value, the AI copied them as they are. Nothing was wrong in this run.

[7] Switch to a page that lacks the information: no author, no publish time, no image, only a date as plain text. The prompt now drops "do not make up values" and asks for all recommended properties.

page2.html
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Growing lettuce on a balcony | Moonlight Farm Blog</title><link rel="canonical" href="https://example.com/blog/balcony-lettuce/"></head><body><article><h1>Growing lettuce on a balcony</h1><p>Pot size and watering interval.</p><p>October 20, 2026</p></article></body></html>
prompt.2.txt
Below is the HTML of one blog post. Write its schema.org Article JSON-LD. Fill in all the recommended properties from Google's documentation (author, datePublished, dateModified, headline, image).- Output a single JSON object only. No explanation, no code fences.
console
$ cat prompt.2.txt page2.html > in.2.txt$ claude -p --model sonnet --max-turns 1 < in.2.txt > out.2.json$ cat out.2.json{"@context":"https://schema.org","@type":"Article","headline":"Growing lettuce on a balcony","description":"Pot size and watering interval.","datePublished":"2026-10-20","dateModified":"2026-10-20","author":{"@type":"Organization","name":"Moonlight Farm"},"publisher":{"@type":"Organization","name":"Moonlight Farm"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://example.com/blog/balcony-lettuce/"},"url":"https://example.com/blog/balcony-lettuce/","inLanguage":"en"}

[8] Run the same script.

console
$ python3 -I check_jsonld.py page2.html out.2.json; echo "exit $?"WARN missing imageWARN datePublished has no timezone: '2026-10-20'WARN dateModified has no timezone: '2026-10-20'FAIL datePublished '2026-10-20' not found in page <time>: []FAIL dateModified '2026-10-20' not found in page <time>: []FAIL author.name 'Moonlight Farm' not in page byline: []3 fail, 3 warnexit 1

This time the model left out image but still wrote a dateModified the page has no record of, copied from the publish date, and filled author with the organization. The script reads <time datetime>, so the plain-text date also fails; a date that is not machine-readable on the page cannot be matched. Fix the page, not the JSON-LD: put the real author, modified date and image on the page and regenerate, or drop the properties you cannot support. Google's documentation requires none of them.

[9] To see that format errors are caught too, break out.1.json by hand (these errors are not from the model). The first file has a @type typo and a changed date format; the second has the timezone removed and the headline changed.

console
$ python3 -I check_jsonld.py page.html bad1.json; echo "exit $?"FAIL @type: 'Artcle'FAIL datePublished not ISO 8601: '2026.10.12'2 fail, 0 warnexit 1$ python3 -I check_jsonld.py page.html bad2.json; echo "exit $?"WARN datePublished has no timezone: '2026-10-12T09:30:00'FAIL headline differs from h1: 'Winter tomatoes' vs 'Growing tomatoes on a winter balcony'FAIL datePublished '2026-10-12T09:30:00' not found in page <time>: ['2026-10-12T09:30:00+09:00', '2026-10-25T14:05:00+09:00']2 fail, 1 warnexit 1

The exit code is 1 for any FAIL, 2 for a parse error and 0 for a pass, so it drops straight into a build script.

#seo#structured-data#json-ld#python