Render JSON-LD from a Server Component as a script of type application/ld+json, and replace every < in the serialized string with \u003c before it goes into the HTML. Build the object only from facts the page already shows. Next.js documents this pattern for page.tsx and layout.tsx in the App Router (Next.js JSON-LD guide, last updated February 27, 2026).

Server-rendered markup sits in the first HTML response, so you can read it with view source before any client JavaScript runs. Google says it can process structured data that JavaScript adds to the rendered page, and its guidance still recommends including structured data in server-rendered output when you use server-side rendering (Google JavaScript structured data guide).

No test guarantees rankings, rich results or AI citations, so each check is about accuracy and availability.

Key takeaways

  1. Render on the serverOutput the script of type application/ld+json from a Server Component in page.tsx or layout.tsx so it is in the first HTML response.
  2. Escape the less-than characterReplace < with \u003c after JSON.stringify, because Next.js warns that ordinary serialization does not sanitize malicious strings.
  3. Match visible contentBuild the object from facts the page shows. Google and Bing both say markup must accurately represent visible content.
  4. Article has no required fieldsGoogle's Article feature lists no required properties and recommends headline, image, author and dates where they apply.
  5. Test the deployed URLCheck the final HTML, then use the Rich Results Test, Schema Markup Validator and Bing URL Inspection. No test guarantees results.

JSON, JSON-LD and Schema.org

JSON is a text format of keys and values: objects, arrays, strings, numbers, booleans and null. Run it through a parser to confirm the syntax is valid.

JSON-LD is JSON with a few reserved keys for Linked Data, defined by the W3C (JSON-LD 1.1 specification). @context names the vocabulary, @type names the kind of thing described, and @id gives that thing a stable identifier. Schema.org is the shared vocabulary of types and properties, so Article and headline come from Schema.org while the @ keys come from JSON-LD.

Structured data is machine-readable information that describes what a page already says. It does not add visible content. Google recommends JSON-LD because it is easier to maintain at scale, and its guidelines say the markup must match visible page content and that a rich result is never guaranteed (Google structured data introduction, Google general guidelines).

Render JSON-LD from a Server Component in the App Router

Next.js recommends a <script> element in layout.js or page.js. Use page.tsx for facts about one page, such as an article, and layout.tsx for facts that repeat across a section of the site, such as the publisher organization. A Server Component runs on the server, so the script lands in the HTML the browser receives.

The example below is the Next.js pattern with fictional data. It builds one object, serializes it, escapes the less-than character and renders the script next to the visible heading.

tsx
const jsonLd = {
  "@context": "https://schema.org",
  "@type": "Article",
  "@id": "https://example.com/articles/rendering-json-ld#article",
  "url": "https://example.com/articles/rendering-json-ld",
  "headline": "Rendering JSON-LD in a Server-Rendered React Site",
  "description": "A fictional guide to rendering safe JSON-LD in React.",
  "image": [
    "https://example.com/images/json-ld-1x1.jpg",
    "https://example.com/images/json-ld-4x3.jpg",
    "https://example.com/images/json-ld-16x9.jpg"
  ],
  "author": {
    "@type": "Person",
    "@id": "https://example.com/about/example-author#person",
    "name": "Example Author",
    "url": "https://example.com/about/example-author"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://example.com/#organization",
    "name": "Example Publishing",
    "url": "https://example.com"
  },
  "datePublished": "2026-01-10T09:00:00-06:00",
  "dateModified": "2026-02-02T14:30:00-06:00",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://example.com/articles/rendering-json-ld"
  }
};

const jsonLdString = JSON.stringify(jsonLd).replace(/</g, "\\u003c");

export default function Page() {
  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: jsonLdString }}
      />
      <main>
        <h1>Rendering JSON-LD in a Server-Rendered React Site</h1>
      </main>
    </>
  );
}

Replace every example.com value with your own page URL, image URLs, author page and organization. Then make the values match the page: the headline should match the visible heading, the dates should match the byline or the dates shown on the page, and the author should be the person or organization named there. In a real project, read these values from the same source that renders the visible page, so the markup and the text cannot drift apart.

Escape the less-than character before embedding

The Next.js guide warns that ordinary JSON.stringify output does not sanitize malicious strings, which is a cross-site scripting (XSS) risk. XSS means untrusted content gets read as executable markup or script. Inside a script element the browser parses HTML first, so a string value that contains </script> could end the element early. Replacing < with \u003c removes that possibility, and because \u003c is a standard JSON escape, a JSON parser still reads it back as <.

This matters most when a value comes from users or a CMS, such as a post title typed into an editor. It costs one line when the data is fully trusted, so apply it everywhere rather than deciding case by case. A small shared component keeps that line in one place.

tsx
type JsonLdProps = { data: Record<string, unknown> };

export function JsonLd({ data }: JsonLdProps) {
  const json = JSON.stringify(data).replace(/</g, "\\u003c");

  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{ __html: json }}
    />
  );
}

Import JsonLd in any page or layout and pass the object as data. Escaping is one layer, not the whole defense. Next.js says the payload should be assembled from trusted, validated data, so check the type of each CMS value, for example that a date is a date and a URL is a URL, before it enters the object.

Server-render JSON-LD in other React setups

Outside the App Router, the rule is the same: the script should be in the HTML your server or build step produces. For a React application, render the script during server-side rendering or static generation when you can. The JsonLd component above is an ordinary React element, so it works anywhere the surrounding page is rendered to HTML on the server or at build time.

A React app that renders only in the browser is different. Its first HTML response is an empty shell, and any script added in an effect exists only after JavaScript runs. Google can still read it from the rendered page, but you now depend on the script loading, any API requests finishing and the crawler rendering the page. If the markup matters, move it into server rendering or static generation.

React hydration adds one more rule. Hydration is React attaching client behavior to HTML the server already produced, and it expects both sides to agree. Keep the JSON-LD object deterministic, which means no dates, IDs or random values that are generated separately on the server and in the browser. Compute them once from your data and pass them in.

Use a complete Article example and choose its properties

The Article object below is valid JSON-LD with fictional facts and example.com URLs. It is the same object the page component builds, written as plain JSON so you can paste it into a validator.

json
{
  "@context": "https://schema.org",
  "@type": "Article",
  "@id": "https://example.com/articles/rendering-json-ld#article",
  "url": "https://example.com/articles/rendering-json-ld",
  "headline": "Rendering JSON-LD in a Server-Rendered React Site",
  "description": "A fictional guide to rendering safe JSON-LD in React.",
  "image": [
    "https://example.com/images/json-ld-1x1.jpg",
    "https://example.com/images/json-ld-4x3.jpg",
    "https://example.com/images/json-ld-16x9.jpg"
  ],
  "author": {
    "@type": "Person",
    "@id": "https://example.com/about/example-author#person",
    "name": "Example Author",
    "url": "https://example.com/about/example-author"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://example.com/#organization",
    "name": "Example Publishing",
    "url": "https://example.com"
  },
  "datePublished": "2026-01-10T09:00:00-06:00",
  "dateModified": "2026-02-02T14:30:00-06:00",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://example.com/articles/rendering-json-ld"
  }
}

Google's Article documentation names Article, NewsArticle and BlogPosting as supported types and lists no required properties. It recommends adding the ones that apply: headline, image, author (with author.name and author.url), datePublished and dateModified (Google Article structured data). The properties url, description, publisher, mainEntityOfPage and @id are optional for that Google feature. Each belongs to the Schema.org vocabulary regardless of what Google displays (Schema.org Article).

Whether a property is "required" depends on who is asking. A property can be optional for the Google Article feature and still useful for the Schema.org meaning of the page or for another consumer. Name the consumer before you call a property required. The Article schema guide covers author and date choices in more depth, and the Article schema generator can build the object from a form.

Article properties and what each one means

Hover over or tap a row to highlight it. On small screens the table scrolls sideways.

PropertySchema.org meaningGoogle Article feature statusVisible-content checkExample value
@typeNames the Schema.org typeNot a Google requirement; it names the type so the block can be read.Page is an article or postArticle
headlineSchema.org Article propertyRecommended for this Google featureMatches the visible page headingRendering JSON-LD in a Server-Rendered React Site
imageSchema.org Article propertyRecommended for this Google featureImage appears on the pagehttps://example.com/images/json-ld-16x9.jpg
authorPerson or Organization, with name and urlRecommended for this Google featureMatches the byline shownExample Author
datePublishedSchema.org Article propertyRecommended for this Google featureMatches the publication date shown2026-01-10T09:00:00-06:00
dateModifiedSchema.org Article propertyRecommended for this Google featureMatches the update date shown2026-02-02T14:30:00-06:00

Add a Breadcrumb and a combined graph

Add a BreadcrumbList only when the breadcrumb trail is visible on the page, because the markup must describe what readers can see. The trail below matches a visible path of Articles, then the article title.

json
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "@id": "https://example.com/articles/rendering-json-ld#breadcrumb",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "Articles",
      "item": "https://example.com/articles"
    },
    {
      "@type": "ListItem",
      "position": 2,
      "name": "Rendering JSON-LD in a Server-Rendered React Site",
      "item": "https://example.com/articles/rendering-json-ld"
    }
  ]
}

Google's Breadcrumb feature has its own current requirements, so read its feature page in the Google structured data gallery when you publish, and keep that separate from whether the type is valid in Schema.org BreadcrumbList. The breadcrumb schema guide and the breadcrumb schema generator cover the details.

Two objects on one page can be rendered as two script elements, one per object. To link them, put them in one @graph so the Article can point at the author and publisher by @id instead of repeating them. The graph below keeps the same facts and adds the breadcrumb.

json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Article",
      "@id": "https://example.com/articles/rendering-json-ld#article",
      "url": "https://example.com/articles/rendering-json-ld",
      "headline": "Rendering JSON-LD in a Server-Rendered React Site",
      "description": "A fictional guide to rendering safe JSON-LD in React.",
      "image": "https://example.com/images/json-ld-16x9.jpg",
      "author": { "@id": "https://example.com/about/example-author#person" },
      "publisher": { "@id": "https://example.com/#organization" },
      "datePublished": "2026-01-10T09:00:00-06:00",
      "dateModified": "2026-02-02T14:30:00-06:00",
      "mainEntityOfPage": { "@id": "https://example.com/articles/rendering-json-ld" }
    },
    {
      "@type": "Person",
      "@id": "https://example.com/about/example-author#person",
      "name": "Example Author",
      "url": "https://example.com/about/example-author"
    },
    {
      "@type": "Organization",
      "@id": "https://example.com/#organization",
      "name": "Example Publishing",
      "url": "https://example.com"
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://example.com/articles/rendering-json-ld#breadcrumb",
      "itemListElement": [
        { "@type": "ListItem", "position": 1, "name": "Articles", "item": "https://example.com/articles" },
        { "@type": "ListItem", "position": 2, "name": "Rendering JSON-LD in a Server-Rendered React Site", "item": "https://example.com/articles/rendering-json-ld" }
      ]
    }
  ]
}

In a Next.js page, pass this whole object to the JsonLd component, and the rendered HTML contains one script for the graph. The JSON-LD graph guide explains how @id references work, the JSON-LD schema examples guide has more types to copy, and the Schema Graph Builder can assemble a graph without hand-writing the references.

Do not add FAQPage markup to chase a Google FAQ rich result. Google announced that FAQ rich results would no longer appear starting May 7, 2026, and removed the FAQ feature documentation in June 2026 (Google documentation updates). FAQPage remains a valid Schema.org type, so existing markup is not broken, but the former Google display feature is gone. The FAQ schema guide covers where it still fits.

Add TypeScript types with schema-dts

The schema-dts package provides TypeScript definitions for Schema.org in JSON-LD form. It gives you discriminated unions, autocomplete and stricter type checking, so a misspelled property or a wrong value shape fails in your editor instead of in production. It is maintained by Google but is not an officially supported Google product (schema-dts on GitHub).

tsx
import type { Article, WithContext } from "schema-dts";

const jsonLd: WithContext<Article> = {
  "@context": "https://schema.org",
  "@type": "Article",
  "@id": "https://example.com/articles/rendering-json-ld#article",
  "url": "https://example.com/articles/rendering-json-ld",
  "headline": "Rendering JSON-LD in a Server-Rendered React Site",
  "description": "A fictional guide to rendering safe JSON-LD in React.",
  "image": "https://example.com/images/json-ld-16x9.jpg",
  "author": {
    "@type": "Person",
    "name": "Example Author",
    "url": "https://example.com/about/example-author"
  },
  "datePublished": "2026-01-10T09:00:00-06:00",
  "dateModified": "2026-02-02T14:30:00-06:00"
};

const jsonLdString = JSON.stringify(jsonLd).replace(/</g, "\\u003c");

Install the package as a development dependency, replace the example values, and keep the escaping line. Types catch many structural mistakes, but they do not prove the content is visible, truthful, eligible for a Google feature or accepted by another provider. Pair them with a JSON parse, Schema.org validation, a Google feature test, a look at the rendered HTML and any provider-specific tools you need.

Client-side injection and Google rendering

Google says it can process structured data in the rendered DOM, which is the document structure after a browser or crawler has run JavaScript. That includes data injected by JavaScript. Google also recommends testing the live URL rather than only pasted code, because testing pasted code has JavaScript limitations (Google JavaScript structured data guide).

Server rendering still earns its place. Client injection works when the final rendered page holds valid markup, but it depends on JavaScript executing, API requests finishing, timing and crawler rendering. Tag managers carry the same dependency, and Google specifically warns that product markup generated by a script can make Shopping crawls less frequent or less reliable. The Google Tag Manager schema guide covers that route when a tag manager is the only option.

Two tracks: on the upper one a page card leaves a server already holding a markup tile, on the lower one a bare page card gets its markup tile late after a gear and a clock
Figure 1. Server-rendered markup arrives with the page, while client injection waits for scripts to run.

If your JSON-LD is missing from view source but present in the browser inspector, it is being added after load. View source shows the initial HTML response, while the inspector shows the rendered DOM. Move the script into a Server Component or into static generation, rebuild, and look again. For critical markup, treat server rendering as the default and client injection as the exception.

Test the deployed page

Test the deployed URL, not only the code in your editor, because caching, middleware and hydration can change what visitors and crawlers receive. Start with the cheapest check: fetch the page and confirm the HTML contains the scripts you expect, that each one parses and that there are no duplicates. This snippet does that for one URL.

js
const url = "https://example.com/articles/rendering-json-ld";
const html = await (await fetch(url)).text();

const pattern = /<script type="application\/ld\+json">([\s\S]*?)<\/script>/g;
const blocks = [...html.matchAll(pattern)];

console.log(`${blocks.length} JSON-LD script(s) found`);
blocks.forEach((match, index) => {
  const data = JSON.parse(match[1]);
  console.log(index + 1, data["@type"] ?? "@graph");
});

Replace the URL with a page from your site. The pattern expects the plain attribute order shown, so adjust it if your build adds attributes to the script element. A thrown error means a script holds invalid JSON, and a count above what you intended means a layout and a page are both emitting the same object.

Next, confirm every marked-up fact is visible on the page: the headline, the author name, the dates and each breadcrumb label. Then use the right validator for each question. The Rich Results Test checks eligibility for supported Google features, not every Schema.org property. The Schema Markup Validator checks vocabulary syntax but does not predict Google display. Google Search Console URL Inspection shows the rendered page Google fetched.

A man in glasses and a slate-grey hoodie compares a laptop with a printed sheet of boxes joined by arrows at a table in a shared studio
Figure 2. Compare the rendered page with the markup on the deployed URL, not only the code in the editor.

For other engines, open Bing Webmaster Tools and use Bing URL Inspection, whose Markup card shows the JSON-LD Bing found. Where Yandex visibility matters, use the Yandex Structured Data Validator. Schema Nova's Schema Validator and Schema Checker also check pasted code and live URLs, and the guide to replacing the Structured Data Testing Tool explains which check answers which question. Re-test after any Next.js or React upgrade, hydration change, CMS change or caching change.

Setup steps from data to production

  1. Define visible factsList the headline, author, dates and trail the page actually shows.
  2. Build the typed objectCreate the object from the same data source, with schema-dts types if you use TypeScript.
  3. Serialize safelyRun JSON.stringify, then replace < with \u003c before embedding.
  4. Render on the serverReturn the script from a Server Component, or from server rendering or static generation.
  5. Inspect the final HTMLFetch the deployed page and confirm one parsed script per object, with no duplicates.
  6. Validate, deploy, re-testUse the Rich Results Test and Schema Markup Validator, then re-test after upgrades or caching changes.

Bing supports JSON-LD and validates annotated data against the selected specification (Bing structured data guidance), so the server-rendered block serves it. Web-enabled Copilot uses Bing web results, so Bingbot access, sitemaps and robots.txt matter there (Microsoft Copilot web access).

For ChatGPT search, allow OAI-SearchBot in robots.txt; it is separate from GPTBot (OpenAI crawler documentation). Perplexity documents its crawler and robots.txt setup (Perplexity crawler guide). Keep the visible HTML authoritative, and see whether AI systems use schema markup.

Questions people ask

Does valid JSON-LD guarantee a rich result?

No. Valid markup means the syntax and vocabulary are correct, and Google says correct markup does not guarantee a rich result. Google also decides which Schema.org types can produce a Search feature, and a type with no Google feature is still valid. See the rich results guide for how display features are decided.

Do I need special schema for Google AI Overviews?

Google says AI Overviews and AI Mode require no special Schema.org markup beyond normal Search eligibility. Keep adding accurate markup for the page types you publish, because that statement covers Google Search only, and other consumers document their own behavior.

Should I use schema-dts?

It is a good fit when your team writes TypeScript and builds objects in code, since it catches wrong property names and value shapes while you type. It is optional, and it does not replace testing the rendered page.

Where do I find setup steps for WordPress, Shopify and other platforms?

Hand-built Next.js and React sites follow this page. For platforms, see the guides for WordPress, Yoast versus Rank Math, Shopify, Wix, Squarespace, Webflow, HubSpot and a Google Business Profile website.

What is the difference between JSON and JSON-LD?

JSON is the plain data format. JSON-LD uses the same syntax and adds keys such as @context, @type and @id so the data is read as Linked Data with a named vocabulary like Schema.org.

Quick check

Choose an answer to see feedback. Nothing is scored or saved.

Question 1 of 3

Does valid Schema.org JSON-LD guarantee a Google rich result?

Question 2 of 3

What is the safer step for user-controlled strings inside an inline script?

Question 3 of 3

Google retired its FAQ rich-result display. Is the FAQPage type now invalid?

Glossary

Select a term to see its definition.

JSON. A text format for objects, arrays, strings, numbers, booleans and null.