Free auditStart free
GuideNext.js · Structured data

Next.js structured data

Render JSON-LD from a Next.js page, escape dynamic data safely, and validate Google rich result eligibility.

3 min
read
5
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
In one line

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.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Check it

Render JSON-LD with the App Router

Next.js recommends rendering structured data in a native script tag in 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.

Product JSON-LD in a page component
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>
)
02Checklist

Choose markup Google can use

First2
Start with a Google-supported rich result type that matches the page, such as Product for an actual product detail page. The sample above is Next.js's minimal example, not a complete rich result: Google's product snippet markup requires name plus at least one of review, aggregateRating, or offers. Check the current feature documentation for required properties before adding markup.
Represent information that readers can see on that URL. Do not mark up ratings, availability, product attributes, or organization details that are absent or misleading on the page.
Next2
Keep values current. If price, availability, or product description changes in the rendered page, update the JSON-LD source from the same data record.
Use a native script tag. Next.js notes that next/script is optimized for executable JavaScript; JSON-LD is structured data, not executable code.
Then1
Do not add schema to every route from a global layout when its values describe only one route. Put it at the page or template level that owns the content.
03How it works

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Sources · 5

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • nextjs.org
  • google.com
  1. 01How to implement JSON-LD in your Next.js application | Next.js Documentationnextjs.org · checked 2026-10-24
  2. 02General structured data guidelines | Google Search Centraldevelopers.google.com · checked 2026-10-24
  3. 03Intro to structured data markup in Google Search | Google Search Centraldevelopers.google.com · checked 2026-10-24
  4. 04Product snippet structured data | Google Search Centraldevelopers.google.com · checked 2026-10-24
  5. 05Product structured data | Google Search Centraldevelopers.google.com · checked 2026-10-24
Questions

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.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane