dotnet-source-gen-json

Generate a JsonSerializerContext with JsonSerializable types for .NET 8+ projects.

6|2|Updated Aug 14, 2025
One-click install
npx skills add https://github.com/Im5tu/claude --skill dotnet-source-gen-json
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-source-gen-json
Source: https://github.com/Im5tu/claude/tree/main/skills/dotnet-source-gen-json
Command: npx skills add https://github.com/Im5tu/claude --skill dotnet-source-gen-json

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill streamlines the creation of System.Text.Json source generation for AOT-friendly JSON serialization, reducing runtime reflection and improving startup performance.

Core Features & Use Cases

  • Generate a JsonSerializerContext: automatically creates a {ProjectName}JsonContext class with JsonSerializable types.
  • ASP.NET Core integration: configures HttpJsonOptions to use the generated context for type resolution.
  • Reduce reflection overhead: enables compile-time generation of serialization code for faster startup.

Quick Start

  • Run the dotnet-json-polymorphic skill to prepare polymorphic types for source generation.
  • Identify the target project (ASP.NET Core or library) and ensure .NET 8+ is installed.
  • Allow the skill to create {ProjectName}JsonContext.cs and update Program.cs to hook MyApiJsonContext.Default into the JSON options.

Frequently Asked Questions about dotnet-source-gen-json

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up System.Text.Json source generation for AOT in .NET 8?

System.Text.Json source generation eliminates runtime reflection by generating serialization code at compile time. This approach improves startup performance and produces AOT-friendly JSON codecs for .NET 8+ applications.

How do I configure ASP.NET Core to use a generated JsonSerializerContext?

You configure ASP.NET Core to use a generated JsonSerializerContext by updating Program.cs to hook the context's Default instance into HttpJsonOptions. This ensures the framework uses your compile-time generated type resolution for JSON serialization.

Can I use JSON source generation with polymorphic types in .NET?

You can use JSON source generation with polymorphic types in .NET by preparing them with a polymorphic type skill first. The generated JsonSerializerContext then includes these types as JsonSerializable attributes for AOT-compatible serialization.

Does .NET 8 JSON source generation work for both ASP.NET Core and library projects?

.NET 8 JSON source generation works for both ASP.NET Core and library projects. The generated JsonSerializerContext can be wired into application configuration for web apps or used directly within library code to handle compile-time serialization.

Why does my System.Text.Json serialization cause reflection overhead at startup?

System.Text.Json serialization causes reflection overhead at startup when using default runtime behavior. Switching to source generation creates compile-time JSON codecs, eliminating this reflection and significantly improving application startup performance.