Sub topic 7
Naming entities with @id
This chapter assumes you can write a JSON-LD object with @context and @type. It also assumes you know how to nest one entity inside another, as covered in the previous chapter.
The problem with repeated descriptions
Nesting works well when each entity appears once. Real pages mention the same entity several times. An article names its publisher, and a product page names the same company as its brand. If you nest the full description each time, you copy data. The copies then drift apart, and a consumer cannot tell whether two similar objects are one company or two.
The @id keyword fixes this. It gives an entity a name that other parts of the markup can point to.
What @id means
@id is the identifier of a node, which is the JSON-LD term for any object that describes a thing. Its value is an IRI. An IRI is a URL-like identifier that may include non-ASCII characters. The rule is simple: two nodes with the same @id describe the same thing, and a consumer may merge their properties.
An @id names a thing. It does not have to be a page that loads. https://example.com/#organization identifies a company, and nothing requires that URL to return a description of it.
Defining once and referencing
Describe the entity fully in one place and give it an @id. Everywhere else, use an object that contains only @id. That object is a node reference.
{
"@context": "https://schema.org",
"@type": "Article",
"@id": "https://example.com/cold-coffee#article",
"headline": "How to Brew Cold Coffee",
"publisher": {
"@type": "Organization",
"@id": "https://example.com/#organization",
"name": "Example Coffee Co.",
"url": "https://example.com/"
},
"copyrightHolder": {
"@id": "https://example.com/#organization"
}
}The publisher value defines the organization. The copyrightHolder value is a reference to it. A processor reads both as the same company with one name and one URL.
The next chapter shows how @graph lets you list every entity at the top level and link them all by reference. The identifier mechanism is the same.
Choosing identifiers
A good identifier is absolute, unique to one entity, and stable over time. A common convention is the canonical page URL plus a fragment that names the role of the entity.
| Entity | Example @id | Reason |
|---|---|---|
| Organization | `https://example.com/#organization` | Defined on the home page and reused on every page. |
| WebSite | `https://example.com/#website` | One per site. |
| Article | `https://example.com/cold-coffee#article` | Tied to the page that contains it. |
| Product | `https://example.com/products/kettle#product` | Survives changes to the product copy. |
| Person (author) | `https://example.com/authors/ana#person` | One identifier for the author across all articles. |
The fragment matters because the page and the thing it describes are different entities. If an Organization used https://example.com/ as its @id, then the home page and the company would be the same node. A processor could then merge properties that belong to only one of them.
Treat identifiers as permanent. Changing a URL slug is fine for visitors, but changing the @id makes the entity look like a new thing. Pick the string once and keep it, even if the page moves.
@id compared with url
New authors often use url and @id as if they were interchangeable. They do different jobs.
@idis the name of the node. It is a JSON-LD keyword, so it works on every type.urlis a schema.org property. It points to a web page about the thing.
{
"@context": "https://schema.org",
"@type": "Person",
"@id": "https://example.com/authors/ana#person",
"name": "Ana Torres",
"url": "https://example.com/authors/ana",
"sameAs": "https://www.linkedin.com/in/example-ana"
}Here the fragment-based @id names Ana, and url points to her author page. sameAs points to another page that identifies the same person, and it does not replace @id.
Relative values and the base IRI
If you write "@id": "#organization" or "@id": "coffee-co", a JSON-LD processor resolves the value against a base IRI. For embedded markup, the base is the URL of the document, and it can be changed by a <base> element. The same string then produces a different identifier on each page. "coffee-co" on /guides/a becomes /guides/coffee-co, and on /b it becomes /coffee-co.
Always write absolute IRIs. That also removes any doubt about trailing slashes, because https://example.com/#organization and https://example.com#organization are compared as strings after resolution, and differences in scheme, host case, or path produce different identifiers.
Blank nodes: entities without a name
If a node has no @id, it is anonymous. Nothing can refer to it from elsewhere, and that is often what you want. An Offer inside a Product or a ListItem inside a breadcrumb rarely needs a name.
JSON-LD also allows blank node identifiers, which start with _:.
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Stainless Steel Pour-Over Kettle",
"offers": [
{
"@type": "Offer",
"@id": "_:standard",
"price": "39.90",
"priceCurrency": "EUR"
}
]
}A blank node label is local to the document. _:standard is not an address that another page or another script block can rely on. Use one only when two places in the same document must share a node but you have no public identifier for it. For anything that more than one page or system may mention, assign a real IRI.
Where references resolve
A reference tells a processor "this is the node named X". It does not make the processor fetch anything. The definition has to be in the data the processor is reading.
- Within one JSON-LD block, references resolve reliably.
- Across several
scriptelements on one page, a standards-based JSON-LD or RDF processor treats them as one dataset and merges nodes with the same@id. Not every consumer does this, and search engines do not document their behavior. Put the definition in the same block as its references when the relationship matters to you. - Across pages, the same
@idis a claim of identity. A reference on page B does not load the definition from page A.
Common mistakes
- One identifier for two things. Using the page URL as the
@idof both aWebPageand theOrganizationit describes merges them. - Unstable identifiers. Generating
@idfrom a title, a timestamp, or a database row number that changes on republish breaks identity. - Non-IRI strings.
"@id": "Example Coffee Co."is a relative IRI, and it resolves to a nonsense URL. - Conflicting definitions. Two nodes with the same
@idand differentnamevalues leave consumers to decide which one is correct. - Treating
@idas a ranking signal. It controls identity inside your data. It does not affect rich results on its own.
Exercise
A site's home page defines an Organization with "@id": "https://example.com/". An article page defines a WebPage with "@id": "https://example.com/cold-coffee" and a publisher reference to "https://example.com/". Name one problem with these identifiers and give a corrected pair of identifiers.
Show answer
The Organization shares its @id with the home page, so a processor may merge the company with the page that describes it. Use a fragment to separate them, for example "https://example.com/#organization" for the Organization, and keep "https://example.com/cold-coffee" (or "https://example.com/cold-coffee#webpage") for the WebPage. The publisher reference must then use "https://example.com/#organization". Both identifiers are absolute and stable.