LLMSdocs
English

JSON-LD basics: @context, @type and @id

How schema.org structured data is written in JSON-LD 1.1: the script element that carries it, the four keywords most pages need, and the choice between nesting a node and referring to it by @id.

Type: BeginnerVersionJSON-LD 1.1
On this page
  1. The keywords in the example
  2. Nesting or referencing
  3. Placing the script element
  4. Why JSON-LD rather than Microdata or RDFa
  5. See also
  6. References

JSON-LD is JSON with a few reserved keys, all starting with @, that turn ordinary objects into statements about things. On a web page it usually describes the page itself and the organization behind it in the schema.org vocabulary, so that a search engine can read who published what without parsing the HTML. JSON-LD 1.0 became a W3C Recommendation on 16 January 2014, and JSON-LD 1.1, the current version, on 16 July 2020.

Here is the markup a documentation site at example.com might put on its home page:

HTML
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": "https://example.com/#organization",
      "name": "Example Widgets",
      "url": "https://example.com/",
      "logo": "https://example.com/logo.png"
    },
    {
      "@type": "WebSite",
      "@id": "https://example.com/#website",
      "name": "Example Widgets Documentation",
      "url": "https://example.com/",
      "publisher": { "@id": "https://example.com/#organization" }
    }
  ]
}
</script>
Organization and WebSite nodes in one @graph, inside the page's head or body

The keywords in the example

@context

The context maps the short keys in the document to full IRIs. With "@context": "https://schema.org", a key such as name stands for the schema.org property name, and a type such as Organization for the schema.org type of that name. The context can be a URL, as here, an inline object, or an array of both. One context at the top applies to everything inside it, which is why the two nodes in @graph do not repeat it.

@type

@type says what kind of thing a node is. Its value is a type from the vocabulary, or an array of types when one thing is several at once. Type names in schema.org start with a capital letter (Organization, WebSite, TechArticle) and properties with a lower-case one (name, url, publisher). The schema.org getting started guide describes the type hierarchy.

@id

@id gives a node an identifier, an IRI that other nodes can point to. The specification calls this a node identifier. It does not have to be a page anyone can visit: https://example.com/#organization uses a fragment of the home page URL to name the organization as distinct from the home page itself. A relative value is resolved against the document's base IRI, normally the page URL. A node without @id is a blank node, which can be described but cannot be referred to from another document.

@graph

@graph holds an array of nodes. A top-level object with only @context and @graph is the simplest way to put several top-level things in one script element without nesting one inside another. The specification also uses @graph for named graphs, a feature web pages rarely need.

Nesting or referencing

A property whose value is another thing can hold that thing in full, or hold only its @id. Both describe the same graph. This article nests its publisher:

JSON
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "headline": "Installing Example Widgets",
  "publisher": {
    "@type": "Organization",
    "name": "Example Widgets"
  }
}

Nesting is easier to read when a thing appears once. Referencing by @id, as WebSite does with its publisher in the first example, uses what the specification calls a node reference: an object containing only @id. It avoids repeating the same organization on every page and states that each mention is the same entity. Google says JSON-LD makes nested data easier to express.

Placing the script element

  • Media type. The script element's type is application/ld+json. Browsers do not execute it; it is data.
  • Head or body. Google reads JSON-LD in either, including markup inserted by JavaScript after the page loads.
  • More than one block. A page may carry several script elements; each is a separate JSON-LD document.
  • Escaping. Section 7.2 of the specification asks authors to avoid character sequences that HTML could read as the end of the script, such as </script> inside a string value. Writing < as \u003c inside JSON strings avoids the problem.
  • Valid JSON. A trailing comma or an unescaped quote makes the whole block unreadable. Validating structured data lists the tools that catch this.

Why JSON-LD rather than Microdata or RDFa

Google supports three syntaxes for structured data: JSON-LD, Microdata and RDFa. It says all three are equally fine as long as the markup is valid, and recommends JSON-LD as the easiest to implement and maintain at scale, because the data sits in one block instead of being spread through the HTML as attributes. The vocabulary is the same in all three; only the syntax differs. Which schema.org types suit a documentation site is covered in schema.org types for documentation sites.

See also

  • Schema.org types for documentation sitesWhich schema.org types describe a documentation page and the site around it: TechArticle for the page, BreadcrumbList for its place in the hierarchy, WebSite and Organization for the site and its owner, and SoftwareSourceCode for code examples, with a complete JSON-LD block.
  • Validating structured dataThe Schema Markup Validator checks markup against schema.org; Google's Rich Results Test checks only the features Google Search supports. How to use both, what Search Console adds, and why valid markup can still be ignored.
  • Publishing JSON files: media type, encoding and parsingThe rules a published JSON file has to follow under RFC 8259, how to serve it over HTTP, and how to write, read, format and validate it with Python's json module without producing output that other parsers reject.
  • Machine-readable files a website can publishThe files and markup a site publishes for crawlers, search engines, language model tools and security researchers: what each one is for, where it lives and which document defines it.

References

  1. Kellogg, G., Champin, P.-A. and Longley, D. (eds.) JSON-LD 1.1: A JSON-based Serialization for Linked Data. W3C Recommendation, 16 July 2020 w3.org (accessed 5 December 2026)
  2. JSON-LD 1.0. W3C Recommendation, 16 January 2014 w3.org (accessed 5 December 2026)
  3. Getting started. schema.org schema.org (accessed 5 December 2026)
  4. Introduction to structured data markup in Google Search. Google Search Central developers.google.com (accessed 5 December 2026)