structured-data / linter

Structured Data linter
The Unlicense
88 stars 18 forks source link

No linter output when there's an @id for an @graph #79

Closed jvandriel closed 1 year ago

jvandriel commented 1 year ago

I was playing around with some markup while doing some studying when I noticed the linter doesn't seem to provide any output when there are @ids for @graphs.

Is this an issue with the Linter or am I doing something wrong with this markup?

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@id": "https://example.com/#graph",
  "@graph": [{
    "@type": "OnlineBusiness",
    "@id": "https://example.com/#mainEntityOfPage",
    "name": "Acme Inc.",
    "url": "https://example.com/"
  }, {
    "@type": "Article",
    "@id": "https://example.com/articles/awesome-new-product/#mainEntityOfPage",
    "headline": "Awesome new product",
    "url": "https://example.com/article/awesome-new-product/",
    "about": {
      "@id": "https://example.com/product/explosive-tennis-balls/#mainEntityOfPage"
    },
    "publisher": {
      "@id": "https://example.com/#mainEntityOfPage"
    }
  }]
}
</script>

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@id": "https://example.com/#graph",
  "@graph": [{
    "@type": "Product",
    "@id": "https://example.com/product/explosive-tennis-balls/#mainEntityOfPage",
    "name": "Executive Anvil",
    "aggregateRating": {
      "@type": "AggregateRating",
      "ratingValue": 4.4,
      "reviewCount": 89
    },
    "brand": {
      "@id": "https://example.com/#mainEntityOfPage"
    },
    "subjectOf": {
      "@id": "https://example.com/videos/promo-video/#mainEntityOfPage"
    }
  }, {
    "@type": "VideoObject",
    "@id": "https://example.com/videos/promo-video/#mainEntityOfPage",
    "headline": "The hottest article around.",
    "url": "https://example.com/videos/promo-video/",
    "publisher": {
      "@id": "https://example.com/#mainEntityOfPage"
    }
  }]
}
</script>
gkellogg commented 1 year ago

No, you're not imagining it. The problem is that the embedded JSON-LD is parsed as HTML using RDFa, which doesn't support named graphs. If you parse the JSON-LD directly (say, using the distiller), you'll see the results, and you can lint. Forcing JSON-LD through HTML (at least using the default RDFa parser) is what limits it.

However, JSON-LD natively supports HTML embedding, so this can work, it's just not currently supported in the Linter.

jvandriel commented 1 year ago

Thanks for explaining that @gkellogg. It's good to know I just ran into some technical limitations as opposed to misunderstanding things (again, hehe).