Sub topic 6
Describing related things by nesting
This chapter assumes you can read and write JSON, know how @context and @type declare an entity, and know that schema.org properties expect particular kinds of values. Here you will learn how to describe one thing in terms of another by placing an object inside an object.
Why nesting exists
A real page rarely describes a single isolated thing. An article has an author. A product has a price offer. A company has an address. In schema.org, each of these related things is its own entity with its own type and properties.
JSON-LD expresses the relationship by using a node object (a JSON object that describes an entity) as the value of a property. The outer entity points to the inner entity through that property. The property name says what the relationship is, such as author, offers, or address.
Compare two ways to describe an author:
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"author": "Ana Torres"
}{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"author": {
"@type": "Person",
"name": "Ana Torres",
"url": "https://example.com/authors/ana"
}
}The first version gives a plain string. A machine reads it as a name, but it cannot tell whether the author is a person or an organization, and it has nowhere to attach a URL. The second version states that the author is a Person, and it carries a name and a profile page. Prefer the second form whenever you know more than a name.
The rules of nesting
A nested object follows the same rules as the top-level object.
- It declares its own
@type. - It does not repeat
@context. The context of the outer object applies to everything inside it. - Its properties must make sense for its own type, not for the outer type. A
Personhasnameandurl, but it does not haveheadline.
The property on the outer object also limits what you can nest. Each schema.org property lists the types it expects. author expects a Person or an Organization. offers expects an Offer or an AggregateOffer. Putting an unrelated type there produces a validator warning, and consumers may ignore the value.
Example: a product with an offer
This is the Product example from the plan. The offers property holds an Offer, which holds the price information.
{
"@context": "https://schema.org",
"@type": "Product",
"name": "Stainless Steel Pour-Over Kettle",
"image": "https://example.com/images/kettle.jpg",
"description": "A 1-liter gooseneck kettle for pour-over coffee.",
"offers": {
"@type": "Offer",
"price": "39.90",
"priceCurrency": "EUR",
"availability": "https://schema.org/InStock",
"url": "https://example.com/products/kettle"
}
}Three details in the Offer matter:
priceis a string holding a plain number, with no currency symbol and no thousands separator. The currency goes inpriceCurrencyas a three-letter ISO 4217 code.availabilityis an enumeration value. It is written as a full schema.org URL, not as free text such as"in stock".urlpoints to the page where the offer can be accepted. It is a property of theOffer, not of theProduct.
The price describes the offer, not the product itself. The same kettle could have different offers from different sellers, which is why the model separates the two.
Multiple nested values
Many properties accept more than one value. Use a JSON array of node objects.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"author": [
{
"@type": "Person",
"name": "Ana Torres"
},
{
"@type": "Person",
"name": "Luis Ortega"
}
]
}The array means the article has two authors. The order is not significant in the data model, although some consumers show authors in the order given. A property that holds a single value in your data can still be written as an array with one element, and consumers treat both forms the same.
Several levels deep
Nesting can continue as far as the data requires. Here an article has an author, who works for an organization, which has a postal address.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"author": {
"@type": "Person",
"name": "Ana Torres",
"worksFor": {
"@type": "Organization",
"name": "Example Coffee Co.",
"address": {
"@type": "PostalAddress",
"streetAddress": "12 Roast Street",
"addressLocality": "Lisbon",
"postalCode": "1100-001",
"addressCountry": "PT"
}
}
}
}The chain of properties reads like a sentence: the article's author works for an organization whose address is a postal address. Each step is a relationship, and each step is a separate entity.
Nesting versus a flat list
Nesting works best when each related entity appears once, inside the one entity that owns it. It has costs when the same entity is needed in several places.
Suppose a page describes an article and a website, and both name the same publisher. With nesting alone, you write the full publisher object twice:
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"publisher": {
"@type": "Organization",
"name": "Example Coffee Co.",
"url": "https://example.com/"
},
"isPartOf": {
"@type": "WebSite",
"url": "https://example.com/",
"publisher": {
"@type": "Organization",
"name": "Example Coffee Co.",
"url": "https://example.com/"
}
}
}The duplication has two problems. The copies can drift apart when someone edits one and forgets the other. A machine also cannot be sure the two objects describe the same organization, because nothing marks them as identical. The next chapter shows how @id solves this by giving an entity a name that other objects can refer to.
For now, use nesting when an entity belongs to one parent and is not reused elsewhere on the page.
Common errors
| Mistake | What goes wrong | Fix |
|---|---|---|
| Repeating `@context` in nested objects | Harmless in most cases, but it adds noise and can conflict if the values differ | Declare it once, at the top |
| Omitting `@type` on a nested object | The object has no declared type, so validators cannot check its properties | Always give the nested object a `@type` |
| Using a string where an entity is needed | The value is read as plain text and loses its structure | Replace the string with a node object |
| Putting a property on the wrong object, such as `price` on `Product` | The property is ignored or flagged as unknown for that type | Move it to the `Offer` |
| Nesting a type the property does not accept | A validator warning, and consumers may skip the value | Check the expected types on the property's schema.org page |
| Writing an enumeration as free text | The value is not recognized | Use the full schema.org URL, such as `https://schema.org/InStock` |
Checking your understanding
Exercise
A page shows a pour-over kettle for 39.90 euros, in stock. A colleague wrote "price": "39.90", "priceCurrency": "EUR" directly on the Product object, with no offers property. Explain what is wrong with this and rewrite the offers part correctly.
Show answer
Price and currency are properties of an Offer, not of a Product, so a validator will flag them as unknown on Product and consumers will ignore them. Nest an Offer under offers: "offers": { "@type": "Offer", "price": "39.90", "priceCurrency": "EUR", "availability": "https://schema.org/InStock" }. The price stays a string without a currency symbol, and the availability is the full schema.org URL.
Exercise
You write "author": { "name": "Ana Torres", "url": "https://example.com/authors/ana" } inside an Article. What is missing, and why does it matter?
Show answer
The nested object has no "@type". Without it, the object does not say whether the author is a Person or an Organization, so validators cannot check its properties and consumers cannot interpret it reliably. Add "@type": "Person". The object does not need its own "@context", because the outer object's context applies.
Exercise
An Article names the same publisher in its own publisher property and again inside a nested WebSite. Give one reason why writing the full Organization twice is a problem.
Show answer
The two copies can drift apart when one is edited and the other is not. Also, nothing tells a machine that the two objects describe the same organization. Giving the organization an "@id" and referring to it from both places fixes this, as the next chapter shows.