Search code examples
schema.orgmicrodatajson-ldgoogle-rich-snippetsstructured-data

Structured data: mixing JSON with Microdata causes errors


I'm trying to mark up an article with structured data. For this particular article I've found it a lot cleaner and simpler to use JSON rather than Microdata. In Google's Structured Data Testing Tool this script works fine with no errors:

<script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "Article",
      "mainEntityOfPage": {
         "@type": "WebPage",
         "@id": "https://my_website/my_article.php"
      },
      "author": "My name",
      "name": "My article",
      "headline": "My article",
      "datePublished": "2017-06-10",
      "dateModified": "2017-07-23",
      "image":{"@type":"ImageObject","url":"https://my_website/images/my_logo.png","height":768, "width":782},
      "publisher" : {
          "@type": "Organization", 
          "name": "My site name",
          "logo":{"@type":"ImageObject","url":"https://my_website/images/my_banner.png","height":60, "width":600}
        }
    }

However, the article body is very long so I don't want to put that in the script via articleBody. Instead I've used Microdata:

<div itemscope itemtype="http://schema.org/Article" class="col-md-8">
     <div itemprop="articleBody" class="card">
          <!-- Rest of my HTML -->

As soon as I do this the testing tool gives an error for every single item in my JSON, saying those fields are required.

Is there a way to do this without duplicating 3,000 lines of content into the JSON script articleBody?


Solution

  • You are creating two Article items. The errors are reported for the item created with Microdata, not for the item created with JSON-LD.

    Theoretically, the solution would be to convey that the two Article items describe the same article, not two different articles. This can be done by giving them the same URI as ID: with @id in JSON-LD, with itemid in Microdata (example with JSON-LD and Microdata).

    However, currently Google’s Structured Data Testing Tool doesn’t seem to support this for mixed syntaxes (apart from curious exceptions). When the same syntax is used, it "merges" all items with the same ID.

    There doesn’t seem to be another option.

    If you only care about Google’s Article rich result, note that the articleBody property doesn’t seem to be supported. So you could either omit the Microdata Article item, or you could wait to see if Google manages to show the rich result for your page (from your JSON-LD item) despite having another "incomplete" Microdata item on the page.