Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@id vs. URL for linking JSON-LD nodes

I have defined the publisher Organization on the WebSite node defined on the home page, and I now want to link to that publisher from articles on other pages. However, I also want to link to the WebSite as well, and they naturally share the same @id if I follow the advice of using the URL as the @id.

{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "@id": "http://www.example.com/",
    "url": "http://www.example.com/",
    ...
    "publisher": {
        "@type": "Organization",
        "@id": "http://www.example.com/",  <-- duplicated
        "url": "http://www.example.com/"
    }
}
{
    "@context": "http://schema.org",
    "@type": "WebPage",
    "@id": "http://www.example.com/news",
    "url": "http://www.example.com/news",
    "isPartOf": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
    ...
    "publisher": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
}

I assume IDs must be unique to each node, so is there a best practice for uniquifying IDs such as adding a hash?

{
    "@id": "http://www.example.com/#site",
    ...
    "publisher": {
        "@id": "http://www.example.com/#publisher",
    }
}

If that works, will processors (Google) load the @id to find the rest of the node's properties?

Related to this, is the url property found in many node types assumed to be the @id if missing? I'm ending up duplicating the full URL of the page as the @id and url for most nodes. Is that the norm?

like image 910
David Harkness Avatar asked Dec 10 '16 01:12

David Harkness


1 Answers

@id (JSON-LD)

(and the same goes for itemid in Microdata, and resource in RDFa)

Each thing should get a different URI, and if multiple nodes are about the same thing, they should ideally reuse this URI. Note that these don’t have to be URLs, and they should often not be used as values for Schema.org’s url property (see section below).

Using URI fragments is a common and the most simple way to achieve this. For examples (and other ways), see my answers to these questions:

  • Best practices for adding semantics to a website
  • Concepts for RDFa DRY references
  • RDF 303 redirect clarification
  • Structured Data > Microdata & Json-LD > Entity IDs > Fragment Identifier
  • How to implement “mainEntityOfPage” to this specific site?

For your example case, an organization’s website, the root URL (http://www.example.com/) typically "stands for" three things:

  • the home page
  • the whole website
  • the organization

As the home page is the resource that gets retrieved, it should get the URI http://www.example.com/. The site and the organization should get their own fragments; it’s up to you to choose which ones, e.g.: http://www.example.com/#site for the site, and http://www.example.com/#organization for the organization (FWIW, Apple seems to use #organization, too.)

  • the home page:
    http://www.example.com/

  • the whole website:
    http://www.example.com/#site

  • the organization:
    http://www.example.com/#organization

(Often only two different things are involved: the document, and the thing described by the document. Then the thing often gets a fragment like #this, and in case of persons, #i, but this is just a convention.)

If that works, will processors (Google) load the @id to find the rest of the node's properties?

Google doesn’t document if they try to load those URIs.

Note that there is no requirement that these URIs actually point to a document. You could use HTTP URIs that give 404 answers, or you could use a URI scheme that doesn’t allow retrieval of documents to begin with (e.g., urn, tag, …).

url (Schema.org)

Schema.org’s url property should be used for the URLs that lead to pages that can be visited. It’s not intended as a way to provide an ID, so it’s not necessarily the same URI as provided in @id.

In your example case, you would probably use the same url value for all three things:

  • the home page:
    @id: http://www.example.com/
    url: http://www.example.com/

  • the whole website:
    @id: http://www.example.com/#site
    url: http://www.example.com/

  • the organization:
    @id: http://www.example.com/#organization
    url: http://www.example.com/

like image 133
unor Avatar answered Nov 20 '22 10:11

unor