Skip to content

Your first schema with Core

Core produces the JSON-LD payload. Your application remains responsible for placing it inside the final HTML document.

You need Node.js 22.12 or newer and a TypeScript project.

Terminal window
pnpm add @unschema-graph/core zod

Using npm, yarn, or bun? See all installation commands.

src/schema.ts
import { Article, buildJsonLdGraph, serializeJsonLd } from '@unschema-graph/core';
const article = Article({
headline: 'My first framework-neutral JSON-LD',
image: 'https://example.com/cover.jpg',
datePublished: '2026-09-29',
author: 'Ada Lovelace',
});
const payload = buildJsonLdGraph([article], { graph: false });
const jsonLd = serializeJsonLd(payload, { pretty: true });

Article() validates the input. buildJsonLdGraph() adds the Schema.org context, and serializeJsonLd() escapes characters that could terminate an HTML script element.

jsonLd contains:

{
"@context": "https://schema.org",
"@type": "Article",
"headline": "My first framework-neutral JSON-LD"
}

The actual payload also contains the image, publication date, and author. Insert the serialized string as the text content of one <script type="application/ld+json"> element using your framework’s server-rendering API.

Build Organization, WebSite, and WebPage alongside the article, give shared nodes stable @id values, and call buildJsonLdGraph(items, { baseUrl }) with the complete array.

Build that connected graph.

Learn what builders, entities, identities, and graphs mean, or open the complete Core reference.