GuidesAI search

Tutorial: adding structured data (JSON‑LD) in Astro

By the Banzai Labs teamUpdated on 2 min read

<script type="application/ld+json">{ "@type": "Article", "headline": … }</script>ArticleAuthorDateAn Astro component writes each page’s JSON-LD
JSON-LD is written into the page; engines read the type, author and date from it.

1. The component

---
// src/components/JsonLd.astro
const { data } = Astro.props;
---
<script type="application/ld+json" set:html={JSON.stringify(data)} />

set:html stops Astro from escaping the JSON’s quotes.

2. An article page

---
import JsonLd from '../components/JsonLd.astro';
const article = {
  '@context': 'https://schema.org',
  '@type': 'Article',
  headline: 'Guide title',
  datePublished: '2026-11-12',
  author: { '@type': 'Organization', name: 'Your company' },
};
---
<head>
  <JsonLd data={article} />
</head>

3. Which type, where

Page Type
Home Organization or LocalBusiness
Guide, article Article
Product page Product, with Offer
Every page BreadcrumbList
Questions and answers FAQPage

4. Check

  1. 1The source codeThe JSON-LD block is present and valid.
  2. 2The Rich Results TestGoogle's tool flags errors.
  3. 3Search ConsoleThe enhancements report, after indexing.

Why it helps AI engines: Schema.org for AI search.

Frequently asked questions

Do I need a library?
No. A JavaScript object and JSON.stringify are enough. A types library can help avoid property typos.
Which types come first?
Organization (or LocalBusiness) on the home page, Article on content, Product on product pages, BreadcrumbList everywhere.
Must the data be visible on the page?
Yes. JSON-LD describes what the page shows; announcing something else goes against Google's guidelines.

Read next

All guides