Skip to content

Writing

JSON-LD from SitecoreAI in a Content SDK Next.js App, From Schema Item to Rich Results Test

Muhammad Ali Khan · 30 Nov 2026 · 06 Mins read

JSON-LD from SitecoreAI in a Content SDK Next.js App, From Schema Item to Rich Results Test

For years, structured data on a headless Sitecore site meant one thing: a developer wrote it in React. You read a few route fields, built an Article object by hand, and pushed it into a <script type="application/ld+json"> tag, often through next-seo. Sebastián Aliaga's 2024 post is a good example of that approach. It works. It also means every new schema property is a code change and a deployment.

That changed this autumn. SitecoreAI can now map template fields and site values to Schema.org types in the content tree, and the Layout Service returns the result in sitecore.context.schemas. On 29 October 2026, Content SDK 2.5 for Next.js shipped a JsonLdSchema component that renders it. This post is the setup I'd follow on an existing Content SDK app: configure the schema items, check the Edge response, render it once, and handle the parts the platform doesn't do for you.


What you need

  • A headless SXA site on SitecoreAI. The JSON-LD mapping lives under SXA, so a non-SXA site has nothing to configure.
  • @sitecore-content-sdk/nextjs 2.5 or later. The What's new in Content SDK 2.5 page also asks for @sitecore-content-sdk/cli 2.4.
  • Access to the Content Editor for the site's Settings item.

The platform side arrived first. The SitecoreAI base image 1.10.13 release on 29 September 2026 added a new parameter to a shared base rendering parameters template for component-level JSON-LD. Sitecore warned that because so many renderings inherit from that template, a lot of items could be flagged for republishing, with longer publish times until that settles. If your environment took that image recently, don't be surprised by a slow first publish.


Step 1: Create the Schema items

Everything is driven by items under your site's Settings. The Configure JSON-LD schemas page walks through it. The short version:

  1. Under the site's Settings item, create an item named Schema from /sitecore/templates/Foundation/JSS Experience Accelerator/JSON-LD/Mapping/Schema. SXA doesn't create it for you, and each site needs its own.
  2. For a page schema, add a Template Schema item. Set Schema to a predefined definition such as Article and Template to your page template. Under it, add Template Schema Property items that map a template field to a schema property, for example pageTitle to headline and summary to description.
  3. For a site schema, add a Site Schema item (for example Organization) with Site Schema Property children. These take a static value or an SXA token such as $sitelang.
  4. For a rendering schema, map the rendering's data source template the same way, then turn on Include in schema on the rendering instance in the page.

The schema definitions you pick from live under /sitecore/system/Settings/Foundation/JSS Experience Accelerator/JSON-LD/Schemas/. Pick properties from there rather than typing Schema.org names yourself.

Two rules from the docs are worth keeping in mind while you model this. Template mappings also apply to templates that inherit from the mapped one, so mapping a base page template can reach more pages than you expect. And when two sources produce the same @type, the one with more populated properties wins. If a rendering schema and a page schema both emit Article, you get one of them, not both.


Step 2: Check the Edge response before touching React

I like to confirm the data exists before I debug rendering. The Content SDK's layout service queries Experience Edge with a layout query and reads item.rendered, and it sends the context ID in an x-sitecore-contextid header. You can do the same from a terminal:

curl -s "https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1" \
  -H "Content-Type: application/json" \
  -H "x-sitecore-contextid: $SITECORE_EDGE_CONTEXT_ID" \
  -d '{"query":"query { layout(site: \"my-site\", routePath: \"/news/my-article\", language: \"en\") { item { rendered } } }"}' \
  | jq '.data.layout.item.rendered.sitecore.context.schemas'

Replace the site name, route and language with your own. If you get an array back, the mapping works and the rest is front end. If you get null, the docs say the resolver simply omits schemas when it can't resolve anything, so check the Schema container, the template mapping, and for rendering schemas, the data source and the Include in schema flag.

Remember that this is the published layout. Experience Edge serves what was published, so after you add or change mappings, publish the affected pages and then run the query again. Checking the CM or Pages preview and assuming Edge matches is how you end up with "it works on my machine" for SEO.


Step 3: Render it once

New apps from create-content-sdk-app already include this. The templates now have a src/SitecoreHead.tsx that groups Scripts, SitecoreStyles, PageMetaTags (Pages Router only) and JsonLdSchema, and Layout.tsx renders <SitecoreHead page={page} />.

An existing app doesn't get that file from npm install. The Content SDK docs are clear that updating packages doesn't touch the files generated when you created the app. For a Pages Router app, here is the template's version, which you can copy and adjust to your own import paths:

// src/SitecoreHead.tsx
import { JSX } from 'react';
import { Page, PageMetaTags, JsonLdSchema } from '@sitecore-content-sdk/nextjs';
import Scripts from 'src/Scripts';
import SitecoreStyles from 'src/components/content-sdk/SitecoreStyles';

interface SitecoreHeadProps {
  page: Page;
}

const SitecoreHead = ({ page }: SitecoreHeadProps): JSX.Element => {
  const { layout } = page;
  const { route } = layout.sitecore;

  return (
    <>
      <Scripts />
      <SitecoreStyles layoutData={layout} />
      <PageMetaTags route={route} />
      <JsonLdSchema page={page} />
    </>
  );
};

export default SitecoreHead;

The App Router template is the same minus PageMetaTags, since metadata goes through generateMetadata there. Then in Layout.tsx, swap your separate <Scripts /> and <SitecoreStyles /> lines for <SitecoreHead page={page} />.

If you'd rather not restructure anything, adding <JsonLdSchema page={page} /> anywhere in the layout is enough. The script doesn't need to be inside <head> for crawlers to find it.

Before merging, search the codebase for application/ld+json, JsonLd and next-seo. If a component already builds an Article by hand, you will now ship two Article nodes for the same page. Decide which one owns the data and delete the other.


Step 4: Fill the gaps in code

The platform feature has clear limits, and the docs list them. It maps scalar field values and site-level values. It doesn't build nested objects such as an author with its own @type. There's no per-language configuration, no validation, and no JSON-LD preview in Pages.

Nested objects are the one most people will hit, because Google's article guidance recommends author as a Person or Organization object. You don't have to go back to hand-building everything. getJsonLdSchemas is exported from @sitecore-content-sdk/nextjs, and it does the filtering and the script-safe escaping. So you can take what Sitecore resolved, add to it, and still get one escaped script:

// src/components/StructuredData.tsx
import { JSX } from 'react';
import { Field, Page, getJsonLdSchemas } from '@sitecore-content-sdk/nextjs';

type SchemaNode = Record<string, unknown>;

const withAuthor = (nodes: SchemaNode[], authorName?: string): SchemaNode[] =>
  nodes.map((node) =>
    node['@type'] === 'Article' && authorName && !node.author
      ? { ...node, author: { '@type': 'Person', name: authorName } }
      : node
  );

const StructuredData = ({ page }: { page: Page }): JSX.Element | null => {
  // Same rule JsonLdSchema uses: no structured data in editing, preview or Design Library.
  if (!page.mode.isNormal) return null;

  const { context, route } = page.layout.sitecore;
  const authorField = route?.fields?.authorName as Field<string> | undefined;

  const script = getJsonLdSchemas(withAuthor(context.schemas ?? [], authorField?.value));
  if (!script) return null;

  return <script type={script.type} dangerouslySetInnerHTML={{ __html: script.innerHTML }} />;
};

export default StructuredData;

authorName is a placeholder for whatever field your article template uses. If you use this component, it replaces JsonLdSchema in SitecoreHead. Don't render both, or you're back to duplicate nodes.

Keep the code side small. Every property you add in React is one authors can't see or change in the content tree. My rule would be: if a scalar field can carry it, map it in Sitecore. Only nested or computed values belong in code.


Gotchas worth knowing

You won't see it in Pages. JsonLdSchema returns nothing unless page.mode.isNormal is true, so it's absent in the page builder, preview and Design Library. The docs note that schema resolution itself still runs in editing mode. Test on the published site or a local production-mode build, not inside Pages.

Empty fields disappear. The resolver skips empty values. An Article with an empty pageTitle ships without headline, and nothing warns you. That's a content quality problem, so a required-field rule on the template is the better fix than code.

One config for all languages. Schema configuration isn't per language. A static value on a Site Schema Property is the same in every language version of the site, so if a value has to change per language, that's a job for the code side.

The context ID change in 2.5. Unrelated to JSON-LD, but you'll meet it during the same upgrade. Content SDK 2.5 builds Sitecore stylesheet URLs with the public client context ID, so getHeadLinks() needs NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID. That value ends up in the browser, so don't paste your server context ID there. Per the changelog, a scoped context ID needs at least the Files resource.

Validate the HTML, not the JSON. The docs suggest the Schema Markup Validator and Google's Rich Results Test. Run them against the rendered page URL. A correct schemas array in the Edge response doesn't mean the page renders it.


The order I'd do it in

  1. Upgrade to @sitecore-content-sdk/nextjs 2.5 and @sitecore-content-sdk/cli 2.4, and set the public context ID.
  2. Create the Schema item and one site schema (Organization). Publish, then confirm it with the curl query.
  3. Add SitecoreHead or JsonLdSchema to the layout. Remove any hand-written JSON-LD that now overlaps.
  4. Map one page template, publish a few pages, run the Rich Results Test.
  5. Only then add code for nested properties, using getJsonLdSchemas so escaping stays the SDK's job.

What I like about this feature is that structured data becomes content. Marketing can add a property without waiting for a sprint, and the front end goes back to just rendering what Sitecore sends.


References

Related notes