Skip to content

fix(rules): json-ld-valid accepts an ImageObject for image and logo #463 - #468

Merged
nc9 merged 1 commit into
mainfrom
fix/json-ld-valid-463
Oct 6, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/json-ld-valid-463

Conversation

@nc9

@nc9 nc9 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #463

What was wrong

schema/json-ld-valid typed image (Article, Product, LocalBusiness, Recipe) and Organization.logo as "a string or array of strings". schema.org's range for both is ImageObject | URL, and Google documents both forms, so a nested ImageObject was reported as invalid. On a Nuxt site using @unhead/schema-org it was worse: that library emits one @graph whose nodes link by bare {"@id": ...} references, so Article.author.name, Article.publisher.name and Article.publisher.logo were also reported missing although the referenced nodes carry them.

The same repro surfaced three more defects in this rule:

  • Every validation message was reported twice: once as a validation item and again as a parse-N item, because the parser appends validation messages to schema.errors. That also made the check's message read Invalid JSON-LD syntax for JSON that parsed fine.
  • A wrong-shape value was labelled Article missing image.
  • Validation issues are computed at crawl time and stored in parsedData. A page reused from the crawl cache (304, hash match) keeps the previous release's verdicts, so upgrading would not have cleared the false positive until the page changed or --refresh was passed.

The fix

  • packages/parser/src/schema/validator.ts: new urlOrImage property type for image and logo. It accepts a URL string, an ImageObject (or subtype, schema.org IRI prefixes allowed) with a url or contentUrl, an {"@id"} reference, or an array of these. Numbers, booleans, objects of another @type, {} and an ImageObject with no URL stay invalid.
  • Nested required-field checks (author.name, publisher.name, publisher.logo, offers.*) now read every description of the node's @id on the page, across @graphs and script blocks. A field given by any description counts. A bare reference to an id nothing on the page describes is checked as written, so it still reports. The index walk is iterative (30k-deep nesting tested).
  • packages/rules/src/schema/json-ld-valid.ts: re-validates schemas.all at audit time, falling back to the stored issues only when the parsed schemas were not kept. Drops the Validation: duplicates from the parse-error items (real parse errors keep their parse-N ids), and labels invalid issues <type> has an invalid <property>. Item ids are unchanged.
  • Docs page updated to match (docs/rules/schema/json-ld-valid.mdx).

Cloud note, filed as #474: on a page that still fails this check for another reason (the repro's publisher.logo), the old Article:image and the duplicate parse-N findings stay open as carried findings until the page passes. merge-core carries unmatched prior items while the page is still in the check's failing set. A page that now passes, such as the unhead one, resolves them.

Scope note: thumbnailUrl keeps its string-only check, because its schema.org range is URL. The remaining places where the validator is stricter than Google are filed as #469: single values where it wants arrays, AggregateOffer, and publisher being required.

Evidence (CLI from source, --http -f json --refresh, local fixtures)

Issue repro page, before:

{"status": "fail", "message": "Invalid JSON-LD syntax", "items": [
  {"id": "Article:image", "label": "Article missing image"},
  {"id": "Article:publisher.logo", "label": "Article missing publisher.logo"},
  {"id": "parse-0", "label": "Validation: Article.image must be a string or array of strings"},
  {"id": "parse-1", "label": "Validation: Article.publisher.logo is required"}]}

After (the publisher.logo finding is genuine, and the issue says it is unrelated):

{"status": "fail", "message": "Schema.org validation errors detected", "items": [
  {"id": "Article:publisher.logo", "label": "Article missing publisher.logo"}]}

An @unhead/schema-org-shaped page (Organization identity + #logo ImageObject + WebSite + WebPage + Article + ImageObject + Person, linked by {"@id"}), before:

{"status": "fail", "message": "Invalid JSON-LD syntax", "items": [
  {"id": "Article:author.name"}, {"id": "Article:image"}, {"id": "Article:publisher.logo"},
  {"id": "Article:publisher.name"}, {"id": "Organization:logo"},
  {"id": "parse-0"}, {"id": "parse-1"}, {"id": "parse-2"}, {"id": "parse-3"}, {"id": "parse-4"}]}

After: no schema/json-ld-valid finding (check passes).

Cache reuse: the Nuxt page was crawled by the OLD code, then re-audited by the new code WITHOUT --refresh. The crawl stats show pagesUnchanged: 1, cacheHitsByReason: {"304": 1}, and the reused page's stored parsedData still holds 5 stale _validationIssues. The check passes because the rule re-validates.

Tests

  • New packages/rules/tests/json-ld-valid.test.ts (35 tests) covers:
    • the repro, and every accepted image shape on Article, Product, LocalBusiness, Recipe and Organization.logo;
    • the shapes still rejected, plus missing vs invalid labels;
    • the unhead graph, a graph split across script blocks, a referenced node missing a field, an unresolvable reference, duplicate @id descriptions in both orders, deep nesting;
    • parse-error ids next to validation issues;
    • stale stored issues, and the stored-issue fallback through schemaCollectionFromJSON.
      20 of these fail on main.
  • Also green: schema-graph-flattening, schema-entity-rules, apps/cli/tests/graph/extractors/schema, parse-page, audit-engine/tests/complete-store-parity.
  • tsgo --noEmit clean in packages/parser and packages/rules (and the new test file). oxlint clean on the changed files. [email protected] check --strict passes.

Changelog suggestion

@nc9
nc9 marked this pull request as ready for review October 6, 2026 00:49


image and logo have the schema.org range ImageObject | URL; the validator
only took strings. Bare {"@id"} references now resolve against every
description of that id on the page, so an @unhead/schema-org (Nuxt) graph
validates clean. The rule re-validates at audit time instead of replaying the
issues stored with a crawl-cache-reused page, reports validation messages once
(not again as parse-N items, under an "Invalid JSON-LD syntax" heading), and
labels a wrong-shape value as invalid rather than missing.

Closes #463

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/json-ld-valid-463 branch from 2a3b502 to 1e6e2c6 Compare October 6, 2026 00:49
@nc9
nc9 merged commit eff569d into main Oct 6, 2026
14 checks passed
@nc9
nc9 deleted the fix/json-ld-valid-463 branch October 6, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema/json-ld-valid: nested ImageObject in Article.image is reported as invalid

1 participant