Add JSON-LD structured data to Next.js
Get your product's price, rating and stock into Google and AI answers from the very first HTML response. In the App Router, that means rendering the JSON-LD from a Server Component.
- Render it from a Server Component
- A plain
<script>tag, notnext/script - FullSchema gives you a ready
PageSchemacomponent - Check the raw HTML with
curl, not DevTools
Your page
HoverTap a detail to trace it
Halden
Arc ANC Headphones
4.7 (382 reviews)
Reviews
★★★★★ “Quiet on a full flight, and the battery lasted all week.”
Shipping & returns
Free shipping · 30-day returns
FullSchema reads it and writes the schema search engines and AI read.
halden.audio › products › arc-anc
Arc ANC Headphones
4.7 (382)·$249.00·In stock
Free delivery · 30-day returns
Noise-cancelling headphones under $300?
The Arc ANC Headphones from Halden is $249.00, rated 4.7 from 382 reviews, and in stock with free shipping.
halden.audioexport default async function Page() {const jsonLd = {"@context": "https://schema.org","@graph": [{"@type": "Product","@id": "https://halden.audio/products/arc-anc#product","name": "Arc ANC Headphones","description": "Wireless noise-cancelling headphones with 40-hour battery life.","sku": "HA-ARC-ANC-BLK","image": ["https://halden.audio/images/arc-anc-black.jpg"],"color": "Black","brand": { "@type": "Brand", "name": "Halden" },"aggregateRating": {"@type": "AggregateRating","ratingValue": "4.7","reviewCount": "382"},"review": [{"@type": "Review","author": { "@type": "Person", "name": "Chris T." },"reviewRating": { "@type": "Rating", "ratingValue": "5" },"reviewBody": "Quiet on a full flight, and the battery lasted all week."}],"offers": {"@type": "Offer","url": "https://halden.audio/products/arc-anc","price": "249.00","priceCurrency": "USD","availability": "https://schema.org/InStock","itemCondition": "https://schema.org/NewCondition","seller": { "@id": "https://halden.audio/#org" },"shippingDetails": {"@type": "OfferShippingDetails","shippingRate": {"@type": "MonetaryAmount","value": 0,"currency": "USD"},"shippingDestination": {"@type": "DefinedRegion","addressCountry": "US"},"deliveryTime": {"@type": "ShippingDeliveryTime","handlingTime": {"@type": "QuantitativeValue","minValue": 0,"maxValue": 1,"unitCode": "DAY"},"transitTime": {"@type": "QuantitativeValue","minValue": 2,"maxValue": 4,"unitCode": "DAY"}}},"hasMerchantReturnPolicy": {"@type": "MerchantReturnPolicy","applicableCountry": "US","returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow","merchantReturnDays": 30,"returnMethod": "https://schema.org/ReturnByMail","returnFees": "https://schema.org/FreeReturn"}}},{"@type": "Organization","@id": "https://halden.audio/#org","name": "Halden","url": "https://halden.audio/","logo": "https://halden.audio/images/logo.png"},{"@type": "WebPage","@id": "https://halden.audio/products/arc-anc#webpage","url": "https://halden.audio/products/arc-anc","name": "Arc ANC Headphones | Halden","breadcrumb": {"@id": "https://halden.audio/products/arc-anc#breadcrumb"},"mainEntity": {"@id": "https://halden.audio/products/arc-anc#product"}},{"@type": "BreadcrumbList","@id": "https://halden.audio/products/arc-anc#breadcrumb","itemListElement": [{"@type": "ListItem","position": 1,"name": "Home","item": "https://halden.audio/"},{"@type": "ListItem","position": 2,"name": "Headphones","item": "https://halden.audio/headphones"},{"@type": "ListItem","position": 3,"name": "Arc ANC Headphones"}]}]}return (<script type="application/ld+json"dangerouslySetInnerHTML={{ __html: json }}/>);}An example. FullSchema writes yours from your own page.
Short answer
To add JSON-LD to a Next.js App Router site, render a <script type="application/ld+json"> tag from a Server Component, with the JSON string in dangerouslySetInnerHTML. Don't use next/script or add the tag in useEffect: those inject it on the client, so crawlers that don't run JavaScript miss it. Verify with curl.
- Renders from
- A Server Component
- Avoid
next/script,useEffect- Setup time
- ~2 minutes
By Kadir Yaz · Updated
How to add it
- 1
Generate the schema
Paste your page's live (or deployed preview) URL into FullSchema. On the result, switch the code view to
Next.jsand clickCopy: you get a readyPageSchemaServer Component to save next to the page and render there. - 2
Render it from a Server Component
Render
<PageSchema />in the page, or drop the object into your own JSX. Next.js recommends a plain script tag inlayout.jsorpage.js. Keeping it in a Server Component also keeps the JSON out of your client bundle. What breaks it is adding the tag on the client, inuseEffector withdynamic(..., { ssr: false }): then it isn't in the HTML your server sends, and crawlers that don't run JavaScript never see it.export default async function Page() { const jsonLd = { /* generated schema */ }; return ( <> <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd).replace(/</g, "\\u003c") }} /> {/* rest of the page */} </> ); } - 3
Skip next/script for this specific case
next/scriptis built for JavaScript that runs, like analytics or chat widgets. Its default strategy,afterInteractive, injects the script into the HTML on the client, after hydration starts. JSON-LD is data, not code, so it needs to be in the response your server sends on the first request. A plain<script>tag does that; the Next.js docs say the same. - 4
Verify against the actual HTML response
Don't trust the browser DevTools Elements panel. It shows the DOM after React has run, not the raw response. Run
curlagainst the URL, or useView Page Source, and confirm the script tag is present in that raw HTML.
The raw response tells the truth: a plain script tag is there, the same block through next/script isn't.
Good to know
The same rule applies to Remix, Astro and other server-rendering frameworks: render the schema on the server, don't inject it on the client after the page loads.
For dynamic pages (a specific product or article), generate the JSON-LD inside the page component using the same data you already fetch for the page itself, not a static, hardcoded object.
How to add JSON-LD to Next.js manually
Without FullSchema: what the same result takes by hand.
In Next.js you're writing code either way, so doing it by hand is mostly about getting the data model right.
- 1. Build it from the data you already fetch
- Create the JSON-LD object in the same Server Component that fetches the page's data, so the markup and the page can't drift apart. The
schema-dtspackage gives you TypeScript types for schema.org and catches misspelled properties at build time. - 2. Choose types and fields deliberately
- Pick the most specific schema.org type per route and check Google's documentation for the fields it needs. Leave out values the page doesn't show, even if your database has them.
- 3. Render it safely and check the HTML
- Render a plain
<script type="application/ld+json">from the Server Component and escape<in the serialized JSON. Then check the built page's source, not DevTools, and run a few routes through the Rich Results Test. - 4. Test it like the rest of your code
- Add a test or build step that renders a few representative pages and validates their JSON-LD, so a refactor that renames a field doesn't silently remove your rich results.
- Google: structured data features ↗
- Rich Results Test ↗
- Schema Markup Validator ↗
- Next.js: JSON-LD guide ↗
Weighing this against a plugin or hiring someone? What schema markup costs, every option
What people ask about Next.js schema, answered
Collected from Reddit, the Next.js community and SEO forums. Straight answers, including the cases where you don't need us.
I get a hydration mismatch as soon as I add a JSON-LD script.
A hydration mismatch means the server and the browser rendered different markup. Render a plain <script type="application/ld+json"> with dangerouslySetInnerHTML in a Server Component, the way the Next.js docs show: Server Components don't render again in the browser, so the tag has nothing to mismatch with.
next/script or a plain script tag?
Plain script tag. next/script is for JavaScript that runs; it adds the content to the hydration payload and can defer or move the tag. JSON-LD is inert data and belongs in the server HTML as is. It matters in practice: in our study, on 10 of the 205 JSON-LD pages where we saved the server HTML, the markup wasn't in it and appeared only after JavaScript ran.
Should the schema live in layout.tsx or page.tsx?
Site-wide entities (Organization, WebSite) in the root layout, once. Page-specific types in the page component that already has the data. Don't put Product in a layout that wraps every route.
How do I build the JSON-LD for dynamic routes like /products/[slug]?
Use the same object you fetch for the page: map its fields into the schema object inside the Server Component and serialize with JSON.stringify. Generate one example with FullSchema for a live product URL to see which properties Google actually wants for that type, then template it.
Do I need to escape anything in the JSON?
Replace < with \u003c before injecting, so a value containing </script> can't break out of the tag. The docs' snippet does exactly that.
With ISR or static export, is the schema in the HTML?
Yes, as long as it's rendered as a plain script tag, not injected on the client; the generated HTML contains it. Verify on the deployed URL with View Page Source, not DevTools. If it's missing there but visible in DevTools, something adds it in the browser: next/script, useEffect, or a tag manager.
Not sure what your Next.js pages have today? The site report is free.
Check every page freeNext.js structured data questions
Can I put this in generateMetadata instead?
generateMetadata is for the head metadata Next.js manages for you directly (title, meta tags, OpenGraph); it doesn't have a first-class slot for an arbitrary script tag. Rendering the script directly in your Server Component's JSX is the more direct route and behaves the same way for crawlers.
Why does my schema show up in DevTools but not in view-source?
Something adds the tag in the browser after the page loads: next/script with its default strategy, a useEffect, a component loaded with ssr: false, or a tag manager. It's real in the rendered DOM but absent from the HTML your server sent. Render it as a plain script tag in a Server Component to fix it.
Does this work the same way with the Pages Router?
Yes, same idea: render the script tag as part of the page, or in _document.tsx for something site-wide, rather than injecting it from client-side JavaScript. Pages Router pages are rendered to HTML on the server or at build time either way.
Ready to generate Next.js schema?
Paste your page's URL and FullSchema handles the rest. No dropdowns, nothing to fill in by hand.