11

I have a question about referencing a JSON-LD schema.org markup in another JSON-LD schema.org markup. I have a page with a main event which is located at http://event.com/ and here's the JSON-LD markup for it.

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>

Main event has multiple sub events located at for example http://event.com/sub-event-1/ and here's the JSON-LD markup for that:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>

What I'm trying to do is mark up the subevent as part of the main event. Is it possible to create a reference from the main event to sub event? Something like this:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
  superEvent {
    "url": "http://event.com/"
  }
}
</script>

If it's possible, what's the correct markup for reference. I can't find any information about it.

Or is it required to embed the MainEvent in every single SubEvent like this:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  },
  "superEvent": {
    "@type": "Event",
    "name": "MainEvent",
    "startDate": "2016-04-21T12:00",
    "location": {
    ...
    }
  }
}
</script>
fairport
  • 283
  • 1
  • 3
  • 9

2 Answers2

22

You can identify a node by giving it a URI, specified in the @id keyword. This URI can be used to reference that node.

See the section "Node Identifiers" in the JSON-LD spec.

So your main event could get the URI http://example.com/2016-04-21#main-event:

<script type="application/ld+json">
{
  "@id": "http://example.com/2016-04-21#main-event",
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00"
}
</script>

and you could give this URI as the value for the sub event’s superEvent property:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "superEvent": { "@id": "http://example.com/2016-04-21#main-event" }
}
</script>

(You could of course give your sub event an @id, too. This would allow you and others to identify/reference this sub event.)

unor
  • 92,415
  • 26
  • 211
  • 360
  • I have questions: should I always have the hash #main-event at the end of URL, since I have a page which has many anchor (for example: #abc). So in this case my id will be url#abc or url#abc#main-event. Also if one event has many super events, can I refer multiple ids? –  coinhndp Apr 10 '20 at 10:12
6

What you are looking for a node identifiers (see http://www.w3.org/TR/json-ld/#node-identifiers). You assign each entity a unique identifier in the form of a URL and use it in references:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@id": "http://event.com/#mainEvent",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>

Above you see I gave the event an @id. I appended a fragment (#mainEvent) because http://event.com/ would typically identify the page itself. You can then reference the event as follows:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
  superEvent {
    "@id": "http://event.com/#mainEvent"
  }
}
</script>

Embedding as shown in your example works as well. In that case, you won't need the identifiers as it is clear what references what.

Markus Lanthaler
  • 3,683
  • 17
  • 20
  • How can I refer multiple ids? will the hash #mainEvent cause conflict if my page has anchor tags (in this case I will refer my page url#fb-event#main-event?) –  coinhndp Apr 10 '20 at 10:17