6

If I have the following markup:

<body itemscope="" itemtype="http://schema.org/WebPage">
  <h1 itemprop="name">Lecture 12: Graphs, networks, incidence matrices</h1>
  <p itemprop="description">These video lectures of Professor Gilbert
    Strang teaching 18.06 were  recorded in Fall 1999 and do not
    correspond precisely to the current  edition of the textbook.</p>
  <div itemprop="publisher" itemscope="" itemtype="http://schema.org/CollegeOrUniversity">
    <h4 class="footer">About <span itemprop="name">MIT OpenCourseWare</span></h4>
  </div>
  <a itemprop="license"
    rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
    src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
</body>

And I want to refactor the publisher property because it's complicated and I don't want to necessarily display it and do this:

<body itemscope="" itemtype="http://schema.org/WebPage">
  <h1 itemprop="name">Lecture 12: Graphs, networks, incidence matrices</h1>
  <p itemprop="description">These video lectures of Professor Gilbert
    Strang teaching 18.06 were  recorded in Fall 1999 and do not
    correspond precisely to the current  edition of the textbook.</p>
  <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "CollegeOrUniversity",
        "name": "MIT OpenCourseWare"
    }
</script>
  <a itemprop="license"
    rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
    src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
</body>

How do I say that the <script> block relates to the itemprop="publisher" property?

I guess the two options are i). adding an itemprop attribute to the script tag or ii). adding an @attribute to in lieu of itemprop to the JSON-LD block.

I cannot find documentation on either. Does anyone know the answer?

thisiskatkat
  • 400
  • 1
  • 12
Simon
  • 5,158
  • 8
  • 43
  • 65
  • Where is this `@parent` coming from? It doesn’t seem to be mentioned in the [JSON-LD spec](https://www.w3.org/TR/2014/REC-json-ld-20140116/). – unor Mar 07 '16 at 13:46
  • 1
    @unor I made up the `@parent` attribute as an example. I'll edit the question to clarify this. Sorry to waste your time looking it up in the spec. – Simon Mar 07 '16 at 13:48
  • @unor I think using `` is the way to go. If no other solution is forthcoming I'll accept your answer. My problem is I have lots of `Organization`s and `Person` (People) on my site and I want to optimise reusing their Schema.org blocks. FYI I'm using Jekyll and "data files". I guess I could just use normal HTML block includes instead. – Simon Mar 07 '16 at 13:54
  • Relevant to this question: _"Are you allowed to use different formats on the same page or even mix them up between your desktop and mobile site? Google says it shouldn't be an issue, assuming the actual output is the same on both ends."_ https://www.seroundtable.com/google-formats-schema-22999.html – ptim Jul 23 '19 at 06:51

3 Answers3

2

In pure JSON-LD, this kind of relationship would be expressed by nesting the properties, like this:

   <body>
      <h1>Lecture 12: Graphs, networks, incidence matrices</h1>
      <p>These video lectures of Professor Gilbert
        Strang teaching 18.06 were  recorded in Fall 1999 and do not
        correspond precisely to the current  edition of the textbook.</p>
      <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type" : "WebPage",
            "name" : "Web page name",
            "description" : "Web page desc",
            "license" : "http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US",
            "publisher" : {
                "@context": "http://schema.org",
                "@type": "CollegeOrUniversity",
                "name": "MIT OpenCourseWare"
            }

        }
    </script>
      <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/deed.en_US"><img
        src="/images/cc_by-nc-sa.png" alt="Creative Commons logo with terms BY-NC-SA." /></a>
    </body>

But if you keep WebPage also in your HTML as microdata, you will end up with 2 instances of WebPage when testing in https://developers.google.com/structured-data/testing-tool/ I think it would be better to stick to just microdata or JSON-LD on one page.

thisiskatkat
  • 400
  • 1
  • 12
2

This is not possible like that. If you use the itemprop attribute on the script element, the property value will be the textContent of script. This would be essentially something like itemprop="{ "@context": "http://schema.org", "@type": "CollegeOrUniversity", "name": "MIT OpenCourseWare" }", so the value is the plain text, not JSON-LD (and not interpreted as JSON-LD).

If you don’t want to have the publisher name visible on your page, you could use a meta element:

<div itemprop="publisher" itemscope itemtype="http://schema.org/CollegeOrUniversity">
  <meta itemprop="name" content="MIT OpenCourseWare" />
</div>

It would also be possible to use a node identifier (@id) for the JSON-LD node and reference this URI in Microdata, but some consumers might not support it (some might not follow references at all, some might only recognize what Schema.org expects for the publisher property: Organization/Person, but not URL):

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "CollegeOrUniversity",
    "@id": "http://example.com/mit-opencourseware#thing",
    "name": "MIT OpenCourseWare"
}
</script>
<link itemprop="publisher" href="http://example.com/mit-opencourseware#thing" />
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
0

The whole point of Lined Data is that anyone can say anything anywhere. In this case, you can use @itemid in your Microdata to identify a resource URI and use the same URI as the value (explicit or implicit) of an @id in your JSON-LD. This is certainly how the Steuctured Data Linter interprets it. You'd need to try with Google's Structured Data Testing Tool to see how they interpret it.

If you want to refer to the same resources in Microdata and JSON-LD (or RDFa) this is the only mechanism you have. @itemrel on a script element does not do anything.

Gregg Kellogg
  • 1,831
  • 12
  • 8