Support for JSON-LD in onebox

AI-generated summary

The discussion centers on enhancing Discourse’s onebox feature to support JSON-LD metadata for richer link previews. sam initiated the thread by referencing a prior discussion on rich link previews and highlighted that IMDb provides structured data via JSON-LD (e.g., movie ratings, cast, director, genre), which could improve onebox output beyond standard meta tags. Terrapop extended the idea to video platforms, noting that JSON-LD could serve as a fallback when oEmbed is unavailable, citing a Rumble example. The feature request was successfully implemented, as confirmed by zogstrip, who shared a link to the merged PR on GitHub, marking the addition of JSON-LD support to Discourse’s onebox system. This enhancement allows for more detailed, structured previews from sites that expose JSON-LD data, improving user experience without requiring additional embed endpoints.

Continuing the discussion from Rich link previews with Onebox:

@Anatolia made a request for a richer onebox for Imdb that includes ratings. I think it is a great request but there is a bunch of missing info in the standard embedding meta tags.

On deeper analysis it looks like imdb supports:

In particular:

https://m.imdb.com/title/tt0253474/

Ships:

<script type="application/ld+json">{
  "@context": "http://schema.org",
  "@type": "Movie",
  "url": "/title/tt0253474/",
  "name": "The Pianist",
  "image": "https://m.media-amazon.com/images/M/MV5BOWRiZDIxZjktMTA1NC00MDQ2LWEzMjUtMTliZmY3NjQ3ODJiXkEyXkFqcGdeQXVyNjU0OTQ0OTY@._V1_.jpg",
  "genre": [
    "Biography",
    "Drama",
    "Music",
    "War"
  ],
  "contentRating": "R",
  "actor": [
    {
      "@type": "Person",
      "url": "/name/nm0004778/",
      "name": "Adrien Brody"
    },
    {
      "@type": "Person",
      "url": "/name/nm0470981/",
      "name": "Thomas Kretschmann"
    },
    {
      "@type": "Person",
      "url": "/name/nm0277975/",
      "name": "Frank Finlay"
    },
    {
      "@type": "Person",
      "url": "/name/nm0288976/",
      "name": "Emilia Fox"
    }
  ],
  "director": {
    "@type": "Person",
    "url": "/name/nm0000591/",
    "name": "Roman Polanski"
  },
  "creator": [
    {
      "@type": "Person",
      "url": "/name/nm0367838/",
      "name": "Ronald Harwood"
    },
    {
      "@type": "Person",
      "url": "/name/nm0844262/",
      "name": "Wladyslaw Szpilman"
    },
    {
      "@type": "Organization",
      "url": "/company/co0024473/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0030304/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0053177/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0104170/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0028557/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0047476/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0024879/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0043688/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0049230/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0086499/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0086504/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0074041/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0002254/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0058058/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0031772/"
    },
    {
      "@type": "Organization",
      "url": "/company/co0078675/"
    }
  ],
  "description": "The Pianist is a movie starring Adrien Brody, Thomas Kretschmann, and Frank Finlay. A Polish Jewish musician struggles to survive the destruction of the Warsaw ghetto of World War II.",
  "datePublished": "2002-09-25",
  "keywords": "pianist,holocaust,jewish,survival,poland",
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingCount": 658161,
    "bestRating": "10.0",
    "worstRating": "1.0",
    "ratingValue": "8.5"
  },
  "review": {
    "@type": "Review",
    "itemReviewed": {
      "@type": "CreativeWork",
      "url": "/title/tt0253474/"
    },
    "author": {
      "@type": "Person",
      "name": "Fella_shibby"
    },
    "dateCreated": "2013-09-09",
    "inLanguage": "English",
    "name": "A Masterpiece. Awesome acting by Brody.",
    "reviewBody": "This is a truly heart-wrenching story of one man whose family gets perished in the Holocaust and about his survival over solitude, deprivation, starvation and terror while in hiding during the Nazi occupation. In my opinion it is one of the finest depictions of the holocaust. This movie came close to Schindlers list in depicting the horrors of Holocaust. Brody puts in a marvelous and utterly touching performance. The story depicts the emotional and cultural breakdown of persecuted Jewish community as Nazi policy tightens around them. Excellent acting by Brody.",
    "reviewRating": {
      "@type": "Rating",
      "worstRating": "1",
      "bestRating": "10",
      "ratingValue": "10"
    }
  },
  "duration": "PT2H30M",
  "trailer": {
    "@type": "VideoObject",
    "name": "The Pianist",
    "embedUrl": "/video/imdb/vi988938521",
    "thumbnail": {
      "@type": "ImageObject",
      "contentUrl": "https://m.media-amazon.com/images/M/MV5BMmQ4MWQzNDEtYmI4Zi00NmY0LWEwYTEtZTg4MmQ3MDM2YmJlXkEyXkFqcGdeQXVyNzU1NzE3NTg@._V1_.jpg"
    },
    "thumbnailUrl": "https://m.media-amazon.com/images/M/MV5BMmQ4MWQzNDEtYmI4Zi00NmY0LWEwYTEtZTg4MmQ3MDM2YmJlXkEyXkFqcGdeQXVyNzU1NzE3NTg@._V1_.jpg",
    "description": "Theatrical Trailer from Focus Features",
    "uploadDate": "2008-04-11T16:41:43Z"
  }
}</script>

I wonder if we should teach onebox to support JSON LD for cases like this?

10 Likes

That would be great for videos too, in case no oembed but JSON LD is available:

4 Likes

We got this PR merged :tada:

https://github.com/discourse/discourse/commit/f0c6dd56825d96dce337e709c71d41740cbbca99

4 Likes