9

How do you add more than one schema to a web page?

I am using the Organization and WebSite schemas on my home page. I am writing the markup in JSON-LD format.

The Organization schema for the knowledge graph:

<script type="application/ld+json">
     {
          "@@context": "http://schema.org",
          "@@type": "Organization",
          "name": "My Website Name",
          "url": "http://www.example.com",
          "sameAs": [
               "http://www.facebook.com/example-com",
               "http://www.instagram.com/example-com"
          ]
     }
</script>

and the WebSite schema to include my site name in search results (if Google ever decides to implement this):

<script type="application/ld+json">
     {
          "@context" : "http://schema.org",
          "@@type" : "WebSite",
          "name" : "My Website Name",
          "url" : "http://www.example.com"
     }
</script>

As you can see they both have the same name and url properties.

Do I need to specify the 2 separate like I did or can just concatenate the 2? Any preference of which has to go first on the page?

UPDATE 23 February 2016:

I ended with the following using unor's help:

<script type="application/ld+json">
     {
          "@context": "http://schema.org",
          "@graph": [{
               "@type": "WebSite",
               "name": "My Website Name",
               "url": "http://www.example.com"
          }, {
               "@type": "WebPage",
               "name": "My Website Name",
               "url": "http://www.example.com"
          }, {
               "@type": "Organization",
               "name": "My Website Name",
               "url": "http://www.example.com",
               "sameAs": [
                    "http://www.facebook.com/example-com",
                    "http://www.instagram.com/example-com"
               ]
          }]
     }
</script>
Brendan Vogt
  • 1,115
  • 4
  • 12
  • 22

4 Answers4

10

In JSON-LD (instead of Microdata/RDFa) you have to repeat the property and its value for each node.

Instead of using a separate script element for each node, you could also use a single script element that contains all your nodes as value of @graph. That way you only have to define the @context (and possibly custom properties) one time.

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@graph": 
  [
    {
       "@type": "WebSite"
    },
    {
       "@type": "Organization"
    }
  ]
}
</script>

The order of the script elements (or the nodes in @graph) shouldn’t matter

unor
  • 21,739
  • 3
  • 46
  • 117
  • I edited my original post to include an answer based on your recommendation. I have shared the code that I used for my home page. Could you please comment on the way and nodes that I used. Does it look correct? Any redundant data? – Brendan Vogt Feb 23 '16 at 07:18
  • 2
    Where do you get all your knowledge from regarding structured data? I have searched high and low using Google but never have I found any answers or blog posts with answers like yours. – Brendan Vogt Feb 23 '16 at 07:20
  • any advantage to using @graph vs just passing an array of @type objects? – Ronnie Royston Nov 12 '18 at 22:26
  • 1
    @RonRoyston: I wrote about it in this answer (tl;dr: the disadvantage with the @graph-less array is that you have to repeat the @context per item) – unor Nov 13 '18 at 15:39
4

Not looking to be a necromancer, but there was a recent article from someone at Yoast that details problems that arise with using the @Graph type when trying to get Google search to "report" the subsequent types, especially with Organization data: link

I would recommend breaking out each type into its own "node" for now instead of using @graph as an array, especially since I can't find a single mention of using @graph with JSON-LD in any of Google's Developer documentation.

dan
  • 15,123
  • 11
  • 44
  • 52
I Capulet
  • 843
  • 4
  • 14
  • 3
    Upvoted this, because I can't either. It's almost as if people just started using @graph and I have no idea why. I can't find official documentation on it. – Trace DeCoy May 12 '20 at 11:31
  • It's easier to add itemTypes programmatically when one uses @Graph, so a lot of plugins (e.g. Yoast) ran with it. Doesn't mean it's a good idea though. – I Capulet May 15 '20 at 07:57
0

If you already add website URL in organization, then you don't need to add website schema in your website.

If you're using organization schema, then I suggest to use logo properties as well.

"logo": "http://www.example.com/logo.png"

Another thing, I want to say, Google does not support all the schema and it's properties, so use those schema, which is currently supported by Google.

Goyllo
  • 5,507
  • 1
  • 10
  • 18
-2

You can definitely concatenate them. I have seen it done on a lot of websites. As an example check how it is done on https://yoast.com . And the structured data validation tool from Google seems to say the code is ok.

ClawDuda
  • 1,197
  • 2
  • 12
  • 23