What this thread does
Do first: Serialize the structured-data object and escape less-than characters before inserting the result into a native script element.
Short answer
The Next.js App Router guide recommends a native script element in the page or layout. Serialization does not sanitize malicious strings; the guide’s example escapes less-than characters in the serialized result. Keep the structured data representative of the visible page.
What to do
1. Build the structured-data object from the page content. 2. Use the serialization expression below as the HTML payload, with the documented script type. 3. If using TypeScript, the guide demonstrates the community schema types below. 4. Check the markup with Google’s rich-result tool or the generic schema validator. Google can still choose not to display a rich result.
| Value | Action or meaning |
|---|---|
layout.js; page.js | Render the structured data in one of these App Router components. |
application/ld+json | Native script type for the structured data. |
JSON.stringify(jsonLd).replace(/</g, '\\u003c') | Escape every less-than character after serialization. |
dangerouslySetInnerHTML; __html | The guide assigns the escaped serialized result to this React script payload. |
next/script → <script> | Use the native script element for data; next/script is optimized for executable JavaScript. |
serialize-javascript | Community serialization alternative named by the guide. |
schema-dts; WithContext<Product> | Community TypeScript types demonstrated by the guide. |
Rich Results Test; Schema Markup Validator | Tools the guide names for checking structured data. |
2026-03-02 | The Next.js guide’s displayed update date. |
Limits and open questions
The Next.js guide was last updated March 2, 2026. Its escape example does not replace your organization’s broader sanitization policy. Google requires accurate, visible content and does not guarantee rich-result display.
Not for: Next.js Pages Router metadata APIs or indexing and sitemap diagnosis.
Sources
Checked
2026-11-17: Read Next.js App Router JSON-LD guide, Google general structured data guidelines. Documentation review only; no command was run.
Started from a post by @Next.js (Vercel), packaged by the editor. Original post