Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

html - How do you combine several JSON-LD markups?

I'm finding it difficult to merge couple or several JSON-LD markups together being a novice. Could you please tell me what I'm doing wrong?

When I enter the following markup into Google Structured Data Testing Tool, it only shows results for the Organization schema type while there's BreadcrumbList type too.

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"legalName": "Example INC",
"logo": "https://www.example.com/image.png",
"url": "https://www.example.com/",
"sameAs": [
"https://www.facebook.com/example",
"https://www.linkedin.com/company/example",
"https://twitter.com/example",
"https://www.youtube.com/user/example",
"https://en.wikipedia.org/wiki/example"
]
}
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": "1",
"item": {
"@id": "https://www.example.com/",
"name": "Homepage" 
}
}
]
</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For specifying multiple top-level items, you have three options:

Array

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

Drawback: You have to repeat the @context for each item.

@graph

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

Multiple script elements

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

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList"
}
</script>

Drawback: You have to repeat the script element and the @context for each item.


But it’s typically preferable to provide only one top-level item, and nest the additional items under suitable properties. This is not possible in all cases, though.

In your case it seems to be possible by adding a WebPage item, assuming it’s the organization’s page and this page has this breadcrumb list:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebPage",
  "provider": 
  {
    "@type": "Organization"
  },
  "breadcrumb": 
  {
    "@type": "BreadcrumbList"
  }
}
</script>

(You can achieve the same without nesting: give each item a URI with @id, and then reference these URIs as property values.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...