schemamarkup.wikiThe schema.org and structured data reference

Syntaxes: JSON-LD, Microdata and RDFa

From schemamarkup.wiki, the sourced reference on schema.org and structured data

Schema.org defines a vocabulary, not a file format. Its getting-started guide explains that publishers "use the schema.org vocabulary along with the Microdata, RDFa, or JSON-LD formats to add information to your Web content."[1] All three express the same data model of typed items with properties.[2] Google's general guidelines say that to be eligible for rich results a page must use one of these three formats, and list JSON-LD as recommended.[3] This page compares them, with the same small example in each.

JSON-LD

JSON-LD is "a JSON-based format to serialize Linked Data," defined by the W3C JSON-LD 1.1 specification, a W3C Recommendation dated 16 July 2020.[4] The specification says the syntax "is designed to easily integrate into deployed systems that already use JSON, and provides a smooth upgrade path from JSON to JSON-LD."[4] JSON-LD 1.1 is a superset of JSON-LD 1.0, and except where noted, documents written for version 1.0 remain compatible with 1.1.[4]

In a web page, JSON-LD sits in its own block rather than inside the visible HTML. The specification explains that 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.[4] Google's JavaScript documentation describes inserting such a block with a script or including it in server-side rendered output.[5]

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Plumber",
  "name": "Example Plumbing Co.",
  "telephone": "+1-555-0100"
}
</script>

See JSON-LD basics for the keywords.

Microdata

Microdata is defined in section 5 of the WHATWG HTML Standard. The standard describes it as allowing "nested groups of name-value pairs to be added to documents, in parallel with the existing content."[6] The groups are called items and each name-value pair is a property; an item is created with the itemscope attribute, and a property is added with the itemprop attribute on one of the item's descendants.[6] Schema.org's guide, which teaches Microdata first, adds that the type of an item is given with the itemtype attribute as a URL such as https://schema.org/Movie.[1] The guide notes that Microdata was introduced with HTML5.[1]

<div itemscope itemtype="https://schema.org/Plumber">
  <h1 itemprop="name">Example Plumbing Co.</h1>
  <p>Call <span itemprop="telephone">+1-555-0100</span></p>
</div>

Microdata annotates the visible elements themselves, in parallel with the existing content.[6] For information that cannot be marked up the way it appears, such as a rating shown only as an image of stars or a currency that is implied but not stated, schema.org's guide says to use the meta tag with a content attribute.[1]

RDFa

RDFa adds structured data to HTML with attributes. The W3C's RDFa 1.1 Primer, a Working Group Note in its third edition of 17 March 2015, observes that web content "is increasingly consumed by machines which expect some amount of structured data" and that search engines "have started to provide richer search results by extracting fine-grained structured details from the Web pages they crawl."[7] The full language is defined in the RDFa 1.1 Core, RDFa Lite, XHTML+RDFa 1.1 and HTML5+RDFa 1.1 specifications.[7]

In the Primer's examples, the typeof attribute declares a new data item with a certain type, the vocab attribute sets the vocabulary so that short type and property names can be used, and the property attribute labels content; when the element has an href or src attribute, the property takes that link as its value.[7]

<div vocab="https://schema.org/" typeof="Plumber">
  <h1 property="name">Example Plumbing Co.</h1>
  <p>Call <span property="telephone">+1-555-0100</span></p>
</div>

Comparison

FeatureJSON-LDMicrodataRDFa
Where it livesA separate script block of type application/ld+json[4]Attributes on HTML elements[6]Attributes on HTML elements[7]
Main attributes or keys@context, @type, @id and property names[4]itemscope, itemtype, itemprop[6][1]vocab, typeof, property[7]
SpecificationW3C Recommendation (JSON-LD 1.1)[4]WHATWG HTML Standard[6]W3C RDFa 1.1 specifications[7]
Google rich result supportYes, recommended[3]Yes[3]Yes[3]

Google's tools accept all three: the Rich Results Test "supports structured data in JSON-LD, RDFa, and Microdata."[8] Its review snippet documentation notes one practical difference: in Microdata and RDFa, a content attribute can override the visible text, so a rating shown to readers as "4,4" can be marked up as 4.4.[9] Google's JavaScript guide applies only to JSON-LD generated with JavaScript.[5]

Choosing a syntax

For Google Search the choice affects convenience, not eligibility: all three supported formats qualify, with JSON-LD recommended.[3] Schema.org's data model expects its vocabulary to be used "alongside other vocabulary that shares our basic datamodel and our use of underlying standards like JSON-LD, Microdata and RDFa."[2] Whatever the syntax, Google's quality guidelines require that the markup describe content that is visible on the page; see Google's structured data guidelines.[3]

Google's guidelines on completeness, location and multiple items on a page apply whichever syntax is used.[3] Most examples on schema.org type pages are shown in all three syntaxes, as well as without markup.[1][10]

Common questions

Which syntax should I use?

Google recommends JSON-LD but supports Microdata and RDFa equally for rich result eligibility.[3]

Who defines JSON-LD?

The W3C; JSON-LD 1.1 became a W3C Recommendation on 16 July 2020.[4]

Who defines Microdata?

The WHATWG, in section 5 of the HTML Standard.[6]

References

  1. ^ "Getting started with schema.org using Microdata". Schema.org.
  2. ^ "Data model". Schema.org.
  3. ^ "General structured data guidelines". Google Search Central.
  4. ^ "JSON-LD 1.1: A JSON-based Serialization for Linked Data (W3C Recommendation, 16 July 2020)". World Wide Web Consortium (W3C).
  5. ^ "Generate structured data with JavaScript". Google Search Central.
  6. ^ "HTML Standard, section 5: Microdata". WHATWG.
  7. ^ "RDFa 1.1 Primer". World Wide Web Consortium (W3C).
  8. ^ "Rich Results Test (Search Console Help)". Google Search Console Help.
  9. ^ "Review snippet (Review, AggregateRating) structured data". Google Search Central.
  10. ^ "Organization (type)". Schema.org.