---
title: Schema JSON-LD Nested Graph
category: product
entity_type: skill
price: $15
canonical: https://forgehouse.ai/skills/schema-jsonld-nested-graph/
lang: en
hreflang_alt: https://forgehouse.ai/tr/skiller/schema-jsonld-nested-graph/
last_updated: 2026-06-20
---

# Schema JSON-LD Nested Graph

> Compose typed, nested JSON-LD entity graphs in Astro and Next.js, invalid schema fails to compile, so typos never reach Search Console.

A TypeScript-first system for producing typed, nested JSON-LD entity graphs in Astro and Next.js projects. Using discriminated unions, it composes Article, Product, LocalBusiness, Course, and Service schemas from atomic primitives (Person, Organization, ImageObject) at build time, making invalid schema literally fail to compile, so typos never reach Search Console.

## Use cases
- Generating 5+ schema types from a single typed prop in Astro or Next.js
- Composing nested entity graphs (Article + Author + Publisher + Image)
- Catching schema typos at build time instead of in production
- Producing Rich Results-compliant output for e-commerce, blogs, and catalogs
- Sharing one Organization entity by @id reference across many pages
- Baking structured data at build time with zero runtime cost

## Benefits
- Make invalid schema impossible: wrong @type or missing required field won't compile
- Update a publisher logo once and propagate it across every page automatically
- Ship Rich Results-eligible pages that earn richer, higher-CTR search appearance
- Cut structured-data rework from hours to minutes with composable atomic builders

## What’s included
- Discriminated-union type foundation for five schema types plus atomic primitives
- Builder helper functions for Article, Product, LocalBusiness, Course, and Service
- Astro JsonLd component and Next.js App Router metadata patterns with XSS escaping
- Build-time validation script and package.json CI gate wiring
- @graph and @id entity-reference patterns for entity authority consolidation
- Extensive anti-pattern table covering fake ratings, price formatting, and date handling

## Who it’s for
Frontend and SEO engineers on Astro or Next.js who want type-safe structured data that compiles away invalid states and earns rich results without manual JSON wrangling.

## How it runs
The skill models the schema.org spec as TypeScript discriminated unions so an invalid schema literally does not compile, then composes nested entity graphs (Article, Product, LocalBusiness, Course, Service) from atomic builders and bakes them at build time.
1. Defines the type foundation as a discriminated union over @type literals: choosing Article makes headline, author and datePublished mandatory, and a typo like 'Atricle' is a compile error instead of a Search Console surprise a week later.
2. Builds atomic primitives once (person, organization, imageObject builder functions) and composes compound entities from them, so a publisher logo change is one function edit instead of thousands of page edits.
3. Links recurring entities by @id reference: the publisher Organization or a recurring author Person is defined in a single node and referenced everywhere, so entity authority accumulates in Google's graph instead of fragmenting across pages.
4. Serializes through a JsonLd component that escapes the closing script sequence against XSS injection and wraps multiple schemas (article plus FAQ plus breadcrumb) into a single @graph array.
5. Bakes everything at build time via getStaticPaths or generateStaticParams with hash-memoized output: the same input never serializes twice and runtime cost is zero.
6. Validates in a chain: tsc --noEmit catches type errors locally, a CI script checks spec compliance, the Rich Results CLI tests pre-deploy, Search Console is watched for 7 days post-deploy, and snapshot tests surface silent schema diffs inside PR reviews.

## FAQ
### Does this only work in Astro and Next.js projects?
The builder functions are plain TypeScript, so they compile anywhere TS runs. The shipped pieces, the Astro JsonLd component and the Next.js App Router metadata patterns with XSS escaping, target those two frameworks; elsewhere you wire the output into your own head injection.

### What does 'invalid schema fails to compile' actually mean in practice?
Each schema type is a discriminated union, so a wrong @type or a missing required field is a TypeScript error at build time instead of a Search Console warning weeks later. The graph is also baked at build time, so there's zero runtime cost on the page.

### Will it decide which schema types my pages need?
No. It gives you five composed types (Article, Product, LocalBusiness, Course, Service) plus atomic primitives like Person and Organization, and assumes you know which page gets which. The page-to-schema strategy and the field content stay your job.

## Price
$15, one-time, no subscription. VAT included.

Related guide: [How to automate SEO and AEO with Claude](https://forgehouse.ai/guides/automate-seo-claude/)
