Search code examples
htmlschema.orgjson-ld

Many JSON-LD script elements per page or a single one with nesting?


Let's say we have an ecommerce like Adidas. We have the basic JSON-LD structure for the WebSsite:

{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "url": "https://adidas.com/us",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://adidas.com/us/search?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}

We have the Organization:

{
  '@context': 'http://schema.org',
  '@type': 'Organization',
  'name': 'Adidas',
  'description': 'Sport Shop',
  'email': '[email protected]',
  'url': 'http://www.adidas.us',
  'logo': 'http://www.adidas.us/logo.svg'
}

The website is also a Store:

 "@context":"http://schema.org",
 "@type":"Store",
 "url": 'http://www.adidas.us',
 "description": "Adidas Shop !",
 "name": "Adidas"
}

And we have also the classic BreadcrumbList:

 "@context":"http://schema.org",
 "@type":"BreadcrumbList",
 "itemListElement":
  [  
    {  
       "@type":"ListItem",
       "position":1,
       "item":{  
          "@type":"Thing",
          "@id":"https://www.adidas.us",
          "name":"Adidas"
       }
    },
    {  
       "@type":"ListItem",
       "position":2,
       "item":{  
          "@type":"Thing",
          "@id":"https://www.adidas.us/shoes",
          "name":"Adidas shoes"
       }
    },
    {  
       "@type":"ListItem",
       "position":3,
       "item":{  
          "@type":"Thing",
          "@id":"https://www.adidas.us/shoes/Featured",
          "name":"Adidas featured shoes"
       }
    }
  ]
}

These 3 JSON-LD are common (more or less detailed of course), and sometimes I have found in a webpage 3 script elements with these JSON-LD, sometimes just 1, sometimes 2.

Should we try to nest them into one single script (if so, how !?), or is it better to keep them splitted?


Solution

  • Important is that you connect the entities with suitable properties, not how many script elements you use.

    If you have these three entities on a page, you should convey how they are related. What you probably want to convey: there is a web page that is part of that website, that is published by that organization, and that has that a breadcrumb list.

    So what you are missing is an entity representing the web page (→ WebPage) and properties to connect all your entities (→ publisher, breadcrumb, isPartOf).

    In how many script elements you specify these entities is up to you:

    • One script, nesting all entites.
    • One script, with multiple top-level objects (using @graph and @id).
    • A script per entity (using @id).
    • A combination of the above.

    The first one is the most simple:

    {
      "@context": "http://schema.org",
      "@type": "WebPage",
      "isPartOf": {
        "@type": "WebSite"
      },
      "publisher": {
        "@type": "Organization"
      },
      "breadcrumb": {
        "@type": "BreadcrumbList"
      }
    }
    

    Give each relevant entity an @id, so you can reference these entities on the same page (in the same script element or in other ones), or even on external pages.

    I’m using it here to convey that the same Organization is the publisher of the WebPage as well as the WebSite:

    {
      "@context": "http://schema.org",
      "@type": "WebPage",
      "@id": "",
      "isPartOf": {
        "@type": "WebSite",
        "@id": "/#this-site",
        "publisher": {"@id": "/#this-org"}
      },
      "publisher": {
        "@type": "Organization",
        "@id": "/#this-org"
      },
      "breadcrumb": {
        "@type": "BreadcrumbList"
      }
    }