Next.js structured data
Render JSON-LD from a Next.js page, escape dynamic data safely, and validate Google rich result eligibility.
In Next.js, render JSON-LD in a native <script type="application/ld+json"> inside the relevant page.js or layout.js. Build the object from the page’s real, visible data and escape < in serialized dynamic values to reduce script injection risk. Then validate the deployed URL; valid markup makes a page eligible for some rich results but does not guarantee display.
Where does your site stand?
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
- Free audit in 60 seconds
- Fixes drafted for your review
- ChatGPT, Perplexity, Gemini and AI Overviews tracked
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
- Re-check after big site changes
- Keep this page for reference
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
- Follow the steps below
- Top-traffic pages first
- Check again in a month
3 parts, 3 minutes.
Render JSON-LD with the App Router
layout.js or page.js. Put page-specific data in the page that describes it. For a product route, load the same product record used to render the visible name and description, then build JSON-LD from those values.Next.js notes that JSON.stringify does not sanitize malicious strings used in XSS injection. Its guide demonstrates replacing < with the Unicode escape before placing JSON in the script. It suggests reviewing your organization’s recommended approach to sanitizing dangerous strings, or a community alternative to JSON.stringify such as serialize-javascript. Test the rendered response, not only the object in application code.
const jsonLd = {
"@context": "https://schema.org",
"@type": "Product",
name: product.name,
image: product.image,
description: product.description,
}
return (
<main>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(jsonLd).replace(/</g, "\\u003c"),
}}
/>
<h1>{product.name}</h1>
<p>{product.description}</p>
</main>
)Choose markup Google can use
name plus at least one of review, aggregateRating, or offers. Check the current feature documentation for required properties before adding markup.next/script is optimized for executable JavaScript; JSON-LD is structured data, not executable code.Validate the deployed HTML
When a test passes but no rich result appears, first check the specific Google feature requirements and whether the page qualifies. A green test means the tool did not find technical errors; Google may still choose a plain result.
For framework-level crawl controls, see Next.js XML sitemaps and Next.js robots.txt. For supported page types, see Google’s Product structured data guide.
- 01
Inspect the rendered page
Open the production URL and check its HTML for one JSON-LD script with the expected type and values. Confirm it is present in the initial or rendered DOM that Google can fetch.
- 02
Run a rich result test
Use Google’s Rich Results Test for types Google supports. Use Schema Markup Validator for general schema vocabulary checks that are outside Google rich result eligibility.
- 03
Review Search Console after deployment
Use URL Inspection to confirm Google can access the page and its structured data. Monitor relevant rich result reports for errors after templates or product data change.
- 04
Compare markup with the page
Check a product with variants, unavailable inventory, and missing optional images. Ensure markup describes the actual visible product state on each URL.
Every fact, linked and dated.
nextjs.org
google.com
- 01How to implement JSON-LD in your Next.js application | Next.js Documentationnextjs.org · checked 2026-10-24
- 02General structured data guidelines | Google Search Centraldevelopers.google.com · checked 2026-10-24
- 03Intro to structured data markup in Google Search | Google Search Centraldevelopers.google.com · checked 2026-10-24
- 04Product snippet structured data | Google Search Centraldevelopers.google.com · checked 2026-10-24
- 05Product structured data | Google Search Centraldevelopers.google.com · checked 2026-10-24
Asked a lot.
3 questions people ask next, answered from the sources on this page.
01Where should JSON-LD go in Next.js?
Next.js recommends a native application/ld+json script in the relevant page.js or layout.js. Put page-specific markup in the page that describes it.
02Should I use next/script for JSON-LD?
No. Next.js recommends a native script tag because JSON-LD is structured data rather than executable JavaScript.
03Why does my Next.js schema pass a test but not appear in Google?
A passing test checks many technical requirements but does not guarantee rich result display. Google also checks feature eligibility, page content, policy compliance, and search context.
Tools point. Agencies advise. This one ships.
Run the free audit, then approve the fixes. Every change can be undone.
- 46 fixes shipped without a ticket Brightpipe
- 0→7 ChatGPT citations in six weeks Paylane