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>

4 Answers 4

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

4
  • 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? Commented Feb 23, 2016 at 7: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. Commented Feb 23, 2016 at 7:20
  • any advantage to using @graph vs just passing an array of @type objects? Commented Nov 12, 2018 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
    Commented Nov 13, 2018 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.

2
  • 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. Commented May 12, 2020 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
    Commented May 15, 2020 at 7: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.

-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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.