Sub topic 4
Declaring @context and @type
This chapter assumes you know basic HTML, including the script element, and JSON syntax. It also assumes you know what JSON-LD and schema.org are, as covered in the earlier chapters. Here you learn the two keywords that every schema.org description starts with.
What the two keywords do
A JSON-LD object becomes meaningful through two keywords:
@contexttells a parser which vocabulary the property names come from.@typetells a parser what kind of thing the object describes.
Without @context, a key such as headline is just a string. With "@context": "https://schema.org", a parser maps headline to the schema.org property https://schema.org/headline.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee"
}This object says: "this is an Article, and its headline is How to Brew Cold Coffee."
Writing @context
Put @context once, in the outermost object, as a string. Use https://schema.org. Google and other consumers accept both http and https, but https is the form schema.org recommends.
Nested objects inherit the context from their parent. You do not repeat it.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Brew Cold Coffee",
"author": {
"@type": "Person",
"name": "Ana Torres"
}
}Here the nested Person still uses schema.org because the context applies to the whole tree.
Writing @type
@type takes a schema.org type name. Type names are case-sensitive and start with a capital letter: Article, Person, Product. Property names start with a lowercase letter: headline, name, datePublished.
Pick the most specific type that fits. Schema.org types form a hierarchy, and a subtype inherits every property of its parents. NewsArticle is a kind of Article, which is a kind of CreativeWork, so a NewsArticle may use headline and author.
An entity may have more than one type. Use an array:
{
"@context": "https://schema.org",
"@type": ["Product", "Book"],
"name": "The Coffee Handbook"
}Use this only when the thing truly is both. Do not add types to chase a feature.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Missing `@context` | Keys are not recognized as schema.org properties | Add `"@context": "https://schema.org"` at the top |
| `"@type": "article"` | Unknown type, because names are case-sensitive | Use `"Article"` |
| `"@Type"` or `"type"` | Keyword is ignored or read as a plain property | Use lowercase `@type` |
| `"@context": "schema.org"` | Treated as a relative URL, not the vocabulary | Use the full `https://schema.org` |
| Property used on a type that does not define it | Validators warn or ignore it | Check the type's page on schema.org |
Exercise
This markup is valid JSON but a validator reports no items. Find the two problems and fix them. { "context": "https://schema.org", "@type": "product", "name": "Pour-Over Kettle" }
Show answer
The keyword context is missing its @, so it should be @context. The type name product should be Product, because type names are case-sensitive. The corrected object uses "@context": "https://schema.org" and "@type": "Product".