
System.Text.Json for .NET 11
FreeStreamline JSON handling with .NET 11's new APIs.
Free · Opens the source repo
What System.Text.Json for .NET 11 does
The System.Text.Json skill for .NET 11 provides imperative guidance on utilizing the new JSON serialization features introduced in this version. It focuses on three key APIs: the JsonNamingPolicy.PascalCase, JsonSerializerOptions.GetTypeInfo<T>(), and JsonSerializerOptions.TryGetTypeInfo<T>(out JsonTypeInfo<T>? info). These APIs simplify the process of serializing and deserializing JSON data, particularly when working with PascalCase property names, strongly-typed metadata, and error-free probing of serialization metadata.
This skill is particularly useful for developers working on .NET 11 projects who need to ensure their JSON outputs conform to PascalCase naming conventions without resorting to custom implementations. It eliminates the need for manual adjustments or workarounds, providing a straightforward way to set up serialization options. The skill also enhances type safety by allowing developers to retrieve type metadata directly as JsonTypeInfo<T>, which reduces the risk of runtime errors associated with type casting.
Additionally, the skill addresses the common scenario of checking for the availability of serialization metadata without throwing exceptions. By using TryGetTypeInfo<T>, developers can handle cases where type metadata is not resolved without the overhead of exception handling. This makes the code cleaner and more efficient, aligning with modern development practices.
Overall, this skill is designed for .NET developers who want to leverage the latest features of the System.Text.Json library effectively, ensuring they can write clean, maintainable code while adhering to the latest standards in JSON serialization.
When to use it
Use this skill when developing applications targeting .NET 11 that require JSON handling with PascalCase property names and strongly-typed metadata access.
When not to use it
Avoid this skill for projects targeting .NET 10 or earlier, or when using JSON libraries other than System.Text.Json.
What you can build with it
Setting PascalCase Naming
When you need JSON property names in PascalCase, use `options.PropertyNamingPolicy = JsonNamingPolicy.PascalCase;` to ensure correct formatting.
Accessing Strongly-Typed Metadata
To retrieve type metadata as `JsonTypeInfo<T>`, set the `TypeInfoResolver` and call `options.GetTypeInfo<T>()` directly.
Probing Metadata Availability
Use `options.TryGetTypeInfo<T>(out var info)` to check if metadata for a type is available without exceptions.
How to install System.Text.Json for .NET 11
View source1. Install with the skills CLI
npx skills add dotnet/skills/system-text-json-net11 --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by dotnetSystem.Text.Json — .NET 11
Three APIs were added to System.Text.Json in .NET 11. This skill tells you exactly
when to reach for each one, what to write, what not to write, and how to prove the
result runs. Do not describe these APIs to the user — apply them, then run the code and
show the output.
| API | Replaces the pre-.NET-11 workaround of... |
|---|---|
JsonNamingPolicy.PascalCase (static property) | writing a custom JsonNamingPolicy subclass or hand-annotating every member with [JsonPropertyName] |
JsonSerializerOptions.GetTypeInfo<T>() | calling non-generic GetTypeInfo(typeof(T)) and casting to JsonTypeInfo<T> |
JsonSerializerOptions.TryGetTypeInfo<T>(out JsonTypeInfo<T>? info) | wrapping GetTypeInfo in try/catch to probe availability |
Step 0 — Confirm you can target .NET 11
These APIs only exist in the .NET 11 base class library. Before writing code:
- Run
dotnet --list-sdksand confirm an SDK that can targetnet11.0is present — an11.xSDK, or any later SDK (12.x+) that has thenet11.0targeting pack installed. - If no such SDK is available, stop: tell the user these APIs require targeting
net11.0(on the .NET 11 SDK or later) and cannot compile onnet10.0or earlier. Do not fall back to a custom implementation and pretend it is the new API.
Decision table — symptom → do this → never do this
Match the user's request to a row, apply the Do this cell verbatim, and confirm the Verify column before you are done.
| User asks for… | Do this (on net11.0) | Never do this | Verify |
|---|---|---|---|
| PascalCase JSON property names | options.PropertyNamingPolicy = JsonNamingPolicy.PascalCase; | define class …: JsonNamingPolicy; add per-member [JsonPropertyName]; string-case the names yourself | output JSON keys are PascalCase — e.g. "Name", "Age" |
Strongly-typed metadata JsonTypeInfo<T> | set TypeInfoResolver = new DefaultJsonTypeInfoResolver(), then JsonTypeInfo<T> ti = options.GetTypeInfo<T>(); | (JsonTypeInfo<T>)options.GetTypeInfo(typeof(T)) | variable is typed JsonTypeInfo<T>, no cast |
| Probe whether metadata is resolved | if (options.TryGetTypeInfo<T>(out var ti)) { … } else { … } | try { options.GetTypeInfo<T>(); } catch (…) { … } | no try/catch; both branches handled |
Rule 1 — PascalCase property names
When the user wants JSON output whose property names are PascalCase (Name, Age)
and asks for the built-in / framework-provided way:
- Create or reuse a
JsonSerializerOptionsand setPropertyNamingPolicy = JsonNamingPolicy.PascalCase. - Serialize with those options.
Do not write a JsonNamingPolicy subclass, do not add [JsonPropertyName("…")]
attributes to force casing, and do not upper-case the first letter of each name by
hand. JsonNamingPolicy.PascalCase is the single correct answer on .NET 11.
// Console project (reflection enabled by default). To run this as a file-based app
// (dotnet run app.cs), also set TypeInfoResolver = new DefaultJsonTypeInfoResolver()
// — see "Producing runnable output" below.
using System.Text.Json;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.PascalCase
};
string json = JsonSerializer.Serialize(new { name = "Jane", age = 30 }, options);
Console.WriteLine(json);
// {"Name":"Jane","Age":30}
Rule 2 — Strongly-typed JsonTypeInfo<T>
When the user wants type metadata back as JsonTypeInfo<T> (not the non-generic
JsonTypeInfo that needs a cast):
- Call
options.GetTypeInfo<T>()— it returnsJsonTypeInfo<T>directly. - Assign it to a
JsonTypeInfo<T>variable and use it (e.g. pass it toJsonSerializer.Serialize/Deserialize).
Do not call the non-generic GetTypeInfo(Type) overload and cast the result.
Requires a resolver.
GetTypeInfo<T>()throwsNotSupportedException(NoMetadataForType) unless the options have aTypeInfoResolver— setTypeInfoResolver = new DefaultJsonTypeInfoResolver()for reflection-based apps, or use a source-generatedJsonSerializerContextfor trimmed/AOT apps.
// File-based app (run: dotnet run app.cs). In a .csproj project, remove this line and
// set <TargetFramework>net11.0</TargetFramework> in the project file instead.
#:property TargetFramework=net11.0
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
var options = new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};
JsonTypeInfo<Person> typeInfo = options.GetTypeInfo<Person>();
Console.WriteLine(typeInfo.Type.Name); // Person
record Person(string Name, int Age);
Rule 3 — Probe metadata without throwing
When the user wants to check whether metadata for T is available and branch on it —
without an exception being thrown when it is not:
- Call
options.TryGetTypeInfo<T>(out var info). - Handle the
truebranch (metadata resolved, useinfo) and thefalsebranch (not resolved) explicitly.
Do not wrap GetTypeInfo<T>() in try/catch to detect the missing case — that is
exactly the anti-pattern this API removes. TryGetTypeInfo<T> returns false (instead of
throwing) when no resolver can produce metadata for T, which is precisely the case you
want to branch on.
// File-based app (run: dotnet run app.cs). In a .csproj project, remove this line and
// set <TargetFramework>net11.0</TargetFramework> in the project file instead.
#:property TargetFramework=net11.0
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
// Configured with a resolver → metadata is available.
var configured = new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};
if (configured.TryGetTypeInfo<Person>(out JsonTypeInfo<Person>? info) && info is not null)
{
Console.WriteLine($"Resolved: {info.Type.Name}"); // Resolved: Person
}
else
{
Console.WriteLine("Type info not available");
}
// No resolver → TryGetTypeInfo returns false instead of throwing.
var empty = new JsonSerializerOptions();
Console.WriteLine(empty.TryGetTypeInfo<Person>(out _)); // False
record Person(string Name, int Age);
Producing runnable output on net11.0
The task is not done until the program runs on net11.0 and prints its JSON. Prefer a
console project — reflection-based serialization works there out of the box. A
file-based app also works but has one important caveat (below).
Option A — console project (recommended)
Create a project whose .csproj contains <TargetFramework>net11.0</TargetFramework>,
put the code in Program.cs, then run dotnet run. Confirm the process exits with code 0
and prints the expected JSON.
using System.Text.Json;
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.PascalCase };
Console.WriteLine(JsonSerializer.Serialize(new { name = "Jane", age = 30 }, options));
// {"Name":"Jane","Age":30}
Option B — file-based app (quickest, one caveat)
Save as app.cs, then run dotnet run app.cs; the first directive pins the framework.
Caveat — file-based apps disable System.Text.Json reflection. In a
dotnet run app.csfile-based app,JsonSerializer.IsReflectionEnabledByDefaultisfalse, so plain reflection serialization throwsNotSupportedException(NoMetadataForType). Set an explicitTypeInfoResolver = new DefaultJsonTypeInfoResolver()on the options (as below), or use a source-generatedJsonSerializerContext. A regular project does not need this.
// File-based app (run: dotnet run app.cs). In a .csproj project, remove this line and
// set <TargetFramework>net11.0</TargetFramework> in the project file instead.
#:property TargetFramework=net11.0
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.PascalCase,
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};
Console.WriteLine(JsonSerializer.Serialize(new { name = "Jane", age = 30 }, options));
// {"Name":"Jane","Age":30}
Worked example — serialize with typed metadata + PascalCase
The record below uses lowercase member names on purpose, so the PascalCase policy visibly rewrites them in the output:
// File-based app (run: dotnet run app.cs). In a .csproj project, remove this line and
// set <TargetFramework>net11.0</TargetFramework> in the project file instead.
#:property TargetFramework=net11.0
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.PascalCase,
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
};
JsonTypeInfo<Person> typeInfo = options.GetTypeInfo<Person>();
string json = JsonSerializer.Serialize(new Person("Jane", 30), typeInfo);
Console.WriteLine(json);
// {"Name":"Jane","Age":30}
record Person(string name, int age);
Validation checklist
Before reporting success, confirm every applicable box:
- The project or file-based app targets
net11.0(visible in the.csprojor the#:property TargetFramework=net11.0directive). - PascalCase requests use
JsonNamingPolicy.PascalCase— no customJsonNamingPolicysubclass and no per-member[JsonPropertyName]attributes just to change casing. - Typed-metadata requests use the generic
GetTypeInfo<T>()— no cast of a non-genericJsonTypeInfo— and the options set aTypeInfoResolver(e.g.DefaultJsonTypeInfoResolver) so the call doesn't throwNoMetadataForType. - Probing requests use
TryGetTypeInfo<T>(out …)— notry/catcharoundGetTypeInfo. - The program was actually run (
dotnet run …), exited 0, and its printed JSON shows the expected property names (e.g."Name","Age"). - If a file-based app (
dotnet run app.cs) is used, everyJsonSerializerOptionssets aTypeInfoResolver— file-based apps disable reflection so plain serialization throwsNoMetadataForTypewithout one.
Common pitfalls
| Pitfall | Fix |
|---|---|
Hand-rolling a class … : JsonNamingPolicy for PascalCase | Delete it; set PropertyNamingPolicy = JsonNamingPolicy.PascalCase. |
Adding [JsonPropertyName("Name")] to every member to force casing | Remove the attributes; the naming policy handles all members at once. |
Casting (JsonTypeInfo<T>)options.GetTypeInfo(typeof(T)) | Call the generic options.GetTypeInfo<T>(); no cast needed. |
try { options.GetTypeInfo<T>(); } catch (…) { … } to test availability | Replace with if (options.TryGetTypeInfo<T>(out var info)) { … }. |
NotSupportedException / NoMetadataForType from GetTypeInfo<T>() | The options have no resolver. Set TypeInfoResolver = new DefaultJsonTypeInfoResolver() (reflection) or a source-generated JsonSerializerContext (trim/AOT). |
NoMetadataForType even for a plain Serialize in a dotnet run app.cs file-based app | File-based apps disable STJ reflection. Add TypeInfoResolver = new DefaultJsonTypeInfoResolver(), or run it as a normal project instead. |
| Leaving the app on the SDK's default TFM | Pin net11.0 explicitly so the .NET 11 APIs resolve and the output shows the target. |
| Claiming success without running | Run dotnet run and paste the actual JSON output; the target is a working, executed program. |
More info
- JsonNamingPolicy class — built-in naming policies including
PascalCase - JsonSerializerOptions.GetTypeInfo — typed and non-typed metadata access
- JsonTypeInfo<T> — strongly-typed serialization metadata
- DefaultJsonTypeInfoResolver — reflection-based resolver required by
GetTypeInfo/TryGetTypeInfo - File-based apps —
dotnet run app.csand the#:propertydirective
Frequently asked questions about System.Text.Json for .NET 11
Similar skills
WinMD API Search
Easily find and explore Windows desktop APIs.
WebMCPify
Transform any web app into an agent-ready platform.
Phoenix Tracing
Instrument LLM applications with OpenInference tracing.
Foundry Hosted Agent CopilotKit
Guidance for developing agentic web apps on Azure.
Power Automate Foundation
Connect AI agents to Power Automate seamlessly.
Power Automate Flow Builder
Efficiently build and deploy Power Automate flows programmatically.
