JSON-LD basics
JSON-LD is the syntax Google recommends for structured data,[1] and the one most schema.org examples on this wiki use. It is defined by the W3C JSON-LD 1.1 specification as "a JSON-based format to serialize Linked Data."[2] This page explains the keywords and structures that schema.org markup normally uses. The specification itself covers many more features, such as contexts with custom terms, framing and named graphs, that ordinary web page markup rarely needs.
A JSON-LD document
A JSON-LD document must be valid JSON text, and it must be a single node object, a map consisting only of @context and/or @graph entries, or an array of zero or more node objects.[2] Unlike plain JSON, the keys in a JSON-LD object must be unique, and all keys, keywords and values are case-sensitive.[2] A node object describes the properties of one node in the graph, for example a business, a person or a page.[2]
In schema.org markup, each node usually has a type and a set of properties named after schema.org properties:
{
"@context": "https://schema.org",
"@type": "Plumber",
"name": "Example Plumbing Co.",
"url": "https://www.example.com/",
"telephone": "+1-555-0100"
}
Keywords used in schema.org markup
JSON-LD reserves keywords that begin with the @ sign. The specification defines them as follows:[2]
| Keyword | Meaning in the JSON-LD 1.1 specification |
|---|---|
| @context | Defines the short-hand names, called terms, used throughout a document[2] |
| @type | Sets the type of a node or the datatype of a typed value[2] |
| @id | Uniquely identifies node objects with IRIs or blank node identifiers[2] |
| @graph | Used to express a graph[2] |
| @list | Used to express an ordered set of data[2] |
| @set | Expresses an unordered set of data and ensures values are always arrays[2] |
| @value | Specifies the data associated with a particular property[2] |
| @language | Specifies the language of a string value or the default language of a document[2] |
| @vocab | Expands properties and @type values with a common prefix IRI[2] |
The value "https://schema.org" for @context is what lets short names such as name and telephone stand for full schema.org terms. Schema.org's FAQ says both the https and http forms of the schema.org address are acceptable.[3] See @context, @id and @graph for how identifiers and graphs are used.
Nesting and references
A property value can itself be a node object. The specification calls this embedding and describes it as "a commonly used mechanism for creating a parent-child relationship between two nodes."[2] Without embedding, node objects can be linked by referring to another node's identifier.[2] A node reference is a node object containing only an @id, which may point to a node described elsewhere in the document.[2]
{
"@context": "https://schema.org",
"@type": "Plumber",
"name": "Example Plumbing Co.",
"address": {
"@type": "PostalAddress",
"streetAddress": "100 Example Street",
"addressLocality": "Exampletown",
"postalCode": "00000",
"addressCountry": "US"
}
}
Google's own examples use the same pattern: its local business documentation shows the address as a nested PostalAddress,[4] and its profile page example refers to an author defined elsewhere with an @id reference.[5]
Arrays and multiple values
Any schema.org property can have more than one value; in JSON-LD the values are given as an array.[6] The JSON-LD specification notes that while regular JSON arrays preserve order, JSON-LD arrays are unordered by default unless specifically defined, which is what the @list keyword is for.[2][6] Google's local business documentation also uses an array for the type itself when a business fits several types, for example Electrician, Plumber and Locksmith, and says additionalType is not supported for that purpose.[4]
JSON-LD in an HTML page
JSON-LD "can be easily embedded in HTML by placing it in a script element with the type attribute set to application/ld+json," which creates a data block.[2] Unless a specific script is targeted, all such script elements on a page must be processed and merged into a single dataset, and blank node identifiers in separate script elements are treated as if they were in one document.[2]
Google adds some practical points:
- The Rich Results Test ignores comments inside JSON-LD blocks, but the JSON-LD standard does not support comments, so they may cause errors in actual use; Google says to remove them before publishing.[7]
- For decimal numbers in ratings, use a dot rather than a comma, for example 4.4 rather than 4,4.[8]
- JSON-LD can be generated with JavaScript or a tag manager; Google can process structured data that is in the DOM when it renders the page.[9] Google warns that dynamically generated markup can make Shopping crawls less frequent and less reliable for fast-changing content such as price and availability.[9]
More in Where markup goes on a page.
Common questions
Does the order of properties matter in JSON-LD?
Arrays in JSON-LD are unordered by default; @list is used where order matters.[2]
Can a page have more than one JSON-LD block?
Yes. The specification says all application/ld+json script elements on a page are processed and merged into a single dataset.[2]
Are comments allowed in JSON-LD?
No. The JSON-LD standard does not support them, and Google says to remove them before publishing.[7]
Related topics
References
- ^ "General structured data guidelines". Google Search Central.
- ^ "JSON-LD 1.1: A JSON-based Serialization for Linked Data (W3C Recommendation, 16 July 2020)". World Wide Web Consortium (W3C).
- ^ "Schema.org FAQ". Schema.org.
- ^ "Local business (LocalBusiness) structured data". Google Search Central.
- ^ "Profile page (ProfilePage) structured data". Google Search Central.
- ^ "Data model". Schema.org.
- ^ "Rich Results Test (Search Console Help)". Google Search Console Help.
- ^ "Review snippet (Review, AggregateRating) structured data". Google Search Central.
- ^ "Generate structured data with JavaScript". Google Search Central.