Search code examples
schema.orgjson-ld

How to represent sections of an article with Schema.org in JSON-LD?


I'm new to JSON-LD and even after several hours of searching I still can't find clear answers to some questions.

My website is similar to Wikipedia: it provides lots of information about a specific topic, with lots of smaller sections, long pages, etc. A plain example of how a page is structured:

<article id="animals">
  <header>
    <h1> 1. Animals </h1>
  </header>
  <section id="cats">
    <h2> 1.1 Cats </h2>
    <p> Some information about cats </p>
  </section>
  <section id="dogs">
    <h2> 1.2 Dogs </h2>
    <p> Some information about dogs </p>
  </section>
</article>

I wanted to markup every single section using JSON-LD. Here's how I did it (unnecessary properties left aside):

<script type="application/ld+json">
            {
             "@context": "http://schema.org",
             "@graph": [
            {
              "@type": "CreativeWork",
              "@id": "http://www.example.com/example/#animals",
              "name": "Animals",
              "headline": "Animals",
              "genre": "http://vocab.getty.edu/aat/300048715",
              "url": "http://www.example.com/example/#animals"
            },
            {
              "@type": "CreativeWork",
              "@id": "http://www.example.com/example/#cats",
              "name": "Cats",
              "headline": "Cats",
              "genre": "http://vocab.getty.edu/aat/300048715",
              "url": "http://www.example.com/example/#cats",
              "isPartOf": {
                "@type": "CreativeWork",
                "@id": "http://www.example.com/example/#animals"
              }
            }
             ]
            }
        </script>

1) After many hours of searches I haven't really found of what type these sections should be. Is CreativeWork the right one to use? Is the genre property used correctly?

2) How do specify where the section is located? Is it done using the url property? Can it be done like in this example by indicating the id of the section?

3) I have also noticed that the script gets extremely big if marking up a long page like that. Is it supposed to be like this?


Solution

  • Schema.org doesn’t provide a type for sections/chapters. If you want to specify data about each section anyhow, you should use the CreativeWork type, as this is the most-specific type available for such a case.

    Using genre for these sections can make sense, but I don’t think that http://vocab.getty.edu/aat/300048715 is appropriate. I’m not familiar with this vocabulary, and can’t find a clear definition, but at least the term’s title "articles" suggests that it isn’t suitable for sections of an article.

    Using URLs with fragment identifier for the url property is perfectly fine, and it makes sense to do it like that for sections of an article.

    The whole thing would likely be an Article in your case (or one of its child types), and hasPart/isPartOf can be used to link the Article with the CreativeWork items.

    {
      "@type": "Article",
      "@id": "http://www.example.com/example/#animals",
      "url": "http://www.example.com/example/#animals",
      "name": "Animals",
      "hasPart": [
        {
          "@type": "CreativeWork",
          "@id": "http://www.example.com/example/#cats",
          "url": "http://www.example.com/example/#cats",
          "name": "Cats"
        },
        {
          "@type": "CreativeWork",
          "@id": "http://www.example.com/example/#dogs",
          "url": "http://www.example.com/example/#dogs".
          "name": "Dogs"
        }
      ]
    }
    

    All this can result in a long script, especially if you also want to use articleBody (for the whole article, including all of its sections) and text (for each section), as you have to duplicate/triple much of the content. This is one of the drawbacks of using JSON-LD. You can avoid this problem by using Microdata or RDFa instead. (See a short comparison.)