10

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>
unor
  • 92,415
  • 26
  • 211
  • 360
Iam_Amjath
  • 113
  • 1
  • 8

2 Answers2

24

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

unor
  • 92,415
  • 26
  • 211
  • 360
  • Thanks! I agree with "But it’s typically preferable to provide only one top-level item, and nest the additional items under suitable properties". I was planning to implement the 3rd option which looked redundant with repeated script elements. Also, when I run all your examples through Google structured data testing tool, only the 3rd and 4th (I'm planning to add this) seems to work. Why the top two don't return anything? – Iam_Amjath Jan 17 '18 at 08:00
  • @Iam_Amjath: The first three examples don’t show something in the SDTT because I’ve not added any properties. As soon as you add at least one property per item (e.g., `name`), they should appear. – unor Jan 17 '18 at 08:24
  • Ok. Thanks for letting me know of that. I think I should go back to using separate script elements for most of my need just to be safe. Even leaving out a comma throws errors which is hard me to fix being a novice. Maybe it's time I invest my time in learning JSON properly. – Iam_Amjath Jan 18 '18 at 08:49
  • @Iam_Amjath: Unless you add the data on the client-side via JavaScript, I would recommend to use RDFa or Microdata instead of JSON-LD. It’s easier to type by hand, and you don’t have to duplicate your data on the page, because it reuses the existing markup. – unor Jan 18 '18 at 10:45
  • Interesting. I thought the same and chose JSON-LD which is easier to add to pages and edit unlike Microdata where you need to go after each HTML elements on the page and markup them separately which won't be in close proximity too. It's kind of messed up work for me. I get the duplication part, but I think I'm ok with it now unless we get hold of a fine CMS system that have the (microdata or RDF) markup enabled. Thanks again. – Iam_Amjath Jan 18 '18 at 18:55
2

The JSON is incorrectly concatenated. It would really help if you have a JSON enabled editor (with lint) if you are manually doing it. Atom (https://atom.io) is a good one.

For this particular example, here is the corrected version:

[{
    "@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"
        }
    }]}
]

PS: often simply correctly formatting the code can help spot simple errors as these ones.

Adnan Y
  • 2,982
  • 1
  • 26
  • 29
  • Thanks for your reply and the editor suggestion : -) Btw, Google structured data testing tool is showing errors, any idea why? https://www.screencast.com/t/OQIztCfDtHBt – Iam_Amjath Jan 17 '18 at 07:02
  • @type is duplicate. I have not used the json ld so no sure what it does. However in order to make this valid, you have to know what the data is, which I don't. A simple fix would be to wrap each in a separate object but it might not achieve what you want. Edited to reflect that – Adnan Y Jan 17 '18 at 19:19
  • Thanks again. This one throws error as far as the 'breadcrumb' element is concerned. I better use separate script elements until I grasp a good understating of how JSON works. I appreciate all your help. – Iam_Amjath Jan 18 '18 at 08:51