@context, @id and @graph
Three JSON-LD keywords do most of the structural work in schema.org markup. @context says which vocabulary the short names belong to, @id gives an item an identifier other items can refer to, and @graph holds several items in one document.[1] This page explains each, using the definitions in the W3C JSON-LD 1.1 specification.
@context
The @context keyword defines "the short-hand names that are used throughout a JSON-LD document." These short-hand names are called terms and "help developers to express specific identifiers in a compact manner."[1] In schema.org markup the context is usually the single value "https://schema.org", which maps names such as name, address and telephone to schema.org terms. The related @vocab keyword expands properties and @type values with a common prefix IRI.[1]
JSON-LD documents served with the application/ld+json media type must carry all context information, including references to external contexts, in the body of the document.[1] In practice this means the @context belongs inside each JSON-LD block.
@id
The @id keyword is used "to uniquely identify node objects that are being described in the document with IRIs or blank node identifiers."[1] A node with an @id can be referred to from elsewhere: a node object that contains only @id is a node reference, which "may represent a reference to a node object found elsewhere in the document."[1]
A node that has no identifier, or whose identifier begins with _:, is a blank node. The specification says a blank node "does not contain a de-referenceable identifier because it is either ephemeral in nature or does not contain information that needs to be linked to from outside of the linked data graph."[1]
{
"@context": "https://schema.org",
"@type": "WebPage",
"@id": "https://www.example.com/about#webpage",
"about": { "@id": "https://www.example.com/#organization" }
}
In this example the page refers to an organization by its identifier instead of repeating it. Google's profile page documentation uses the same technique, pointing an article's author to "#main-author".[2] Google's breadcrumb documentation also uses @id: in JSON-LD a ListItem's item can be given as a Thing whose @id is the page URL.[3]
@graph
@graph is "used to express a graph."[1] A JSON-LD document may be a map that consists only of @context and @graph entries, in which case the @graph value holds a list of node objects.[1] This is a convenient way to put several items in one script block:
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://www.example.com/#organization",
"name": "Example Plumbing Co.",
"url": "https://www.example.com/"
},
{
"@type": "WebSite",
"@id": "https://www.example.com/#website",
"url": "https://www.example.com/",
"publisher": { "@id": "https://www.example.com/#organization" }
}
]
}
The same data could be split across separate script blocks, since all application/ld+json blocks on a page are merged into a single dataset.[1] Google's general guidelines still apply to every item: each must describe content on the page and include the required properties for its feature.[4]
Practical notes
- Identifiers are only as stable as the URLs used for them. The specification says @id values are IRIs or blank node identifiers;[1] schema.org's own sameAs property is the separate way to point to other pages that identify an item, such as a Wikidata entry or official website.[5] See sameAs and identifiers.
- Google's Organization guidance recommends putting organization details on the home page or a single page describing the organization, and says they do not need to be on every page.[6]
Across pages
This page covers @id and @graph inside one document. For linking the same Organization, WebSite and WebPage nodes across a whole site, and for the mistakes that break those links, see Entity graphs on business websites. The JSON-LD specification notes that "for nodes to be truly linked, dereferencing the identifier should result in a representation of that node," which is a reason to build @id values on real page URLs.[7]
Common questions
Is @id the same as url?
No. @id is a JSON-LD keyword that identifies a node,[1] while url is a schema.org property meaning "URL of the item."[8]
Do I need @graph?
No. It is one way to group several items; separate script blocks are merged into a single dataset as well.[1]
Related topics
References
- ^ "JSON-LD 1.1: A JSON-based Serialization for Linked Data (W3C Recommendation, 16 July 2020)". World Wide Web Consortium (W3C).
- ^ "Profile page (ProfilePage) structured data". Google Search Central.
- ^ "Breadcrumb (BreadcrumbList) structured data". Google Search Central.
- ^ "General structured data guidelines". Google Search Central.
- ^ "sameAs (property)". Schema.org.
- ^ "Organization (Organization) structured data". Google Search Central.
- ^ "JSON-LD 1.1, section 3.3 Node Identifiers". World Wide Web Consortium (W3C).
- ^ "Thing (type)". Schema.org.