json-serialization
Skill400 starsChanged 10 days agoMITView on GitHub
How this Minimal API reads and writes JSON with System.Text.Json - the one set of options in UseApiDefaults, the source-generated AppJsonSerializerContext, which types it must list, and how tests use the same options. Use when adding a request or response type, changing how JSON looks, or when a value serialises differently than expected.
4 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- LeanMeanCleanApps/CleanLambdaFunctionedited, first seen Nov 15, 2026
- LeanMeanCleanApps/CleanWebApiedited, first seen Nov 15, 2026
- LeanMeanCleanApps/CleanModelContextProtocoltheir own version, first seen Nov 8, 2026
- bkywksj/knowledge-basetheir own version, first seen Oct 8, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 2
- LeanMeanCleanApps/CleanWebApi★ 460% same
- LeanMeanCleanApps/CleanLambdaFunction★ 012% same
Wrote their own version · 2
- bkywksj/knowledge-base★ 340same name
- LeanMeanCleanApps/CleanModelContextProtocol★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- mapping-with-mapperlySkill
- mediatorSkill
- openapi-and-scalarSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 0 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Every request and response goes through System.Text.Json with one set of options, defined once in UseApiDefaults() …
- Very specific: line 28
Add every new request and response type to AppJsonSerializerContext with [JsonSerializable(typeof(...))], including the Page<T> and List<T> …
- Very specific: line 30
Add a test in tests/Presentation.Tests.Unit/Serialization/JsonSerializerOptionsExtensionsTests.cs for any setting you change.
- Very specific: line 31
Never let a response type refer back to its parent.
- Very specific: line 49
Add ReferenceHandler.IgnoreCycles or Preserve to hide a cycle.
- Very specific: line 51
Use [JsonPropertyName] to rename one property.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JSON serialization (Minimal API)
The rule
Every request and response goes through System.Text.Json with one set of options, defined once in UseApiDefaults() (src/Presentation/Serialization/JsonSerializerOptionsExtensions.cs):
| Setting | Effect |
PropertyNamingPolicy = CamelCase | averageStars, not AverageStars |
PropertyNameCaseInsensitive = true | Request bodies are read whatever the case of their property names |
DefaultIgnoreCondition = WhenWritingNull | Null properties are left out of responses |
NumberHandling = Strict | Numbers must be JSON numbers. "5" for an int is refused, and OpenAPI shows integer, not integer | string |
JsonStringEnumConverter(CamelCase) | Enums are written and read as camelCase strings |
Startup applies those options to the Minimal API's JsonOptions and puts AppJsonSerializerContext (src/Presentation/Serialization/AppJsonSerializerContext.cs) first in the resolver chain, so listed types use generated code instead of reflection. The integration tests build their options with the same UseApiDefaults(), so they read responses exactly as a client would.
Responses are trees: lists return summaries, and an entity holds only the flat records it needs. There's no cycle handling, so a cycle fails loudly instead of being quietly cut.
Steps
- Add every new request and response type to
AppJsonSerializerContextwith[JsonSerializable(typeof(...))], including thePage<T>andList<T>forms you return. - Change how JSON looks only in
UseApiDefaults(). Keep the[JsonSourceGenerationOptions]on the context matching it. - Add a test in
tests/Presentation.Tests.Unit/Serialization/JsonSerializerOptionsExtensionsTests.csfor any setting you change. - Never let a response type refer back to its parent. Return a flat record instead (
ReviewAuthor,ReviewedMovie).
Example
// src/Presentation/Extensions/WebApplicationBuilderExtensions.cs
_ = builder.Services.Configure<JsonOptions>(options =>
options.SerializerOptions.UseApiDefaults().TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default));// tests/Presentation.Tests.Integration/Extensions/JsonSerializerExtensions.cs
private static readonly JsonSerializerOptions Options = new JsonSerializerOptions().UseApiDefaults();Don't
- Set serializer options anywhere but
UseApiDefaults(), including in tests. - Add
ReferenceHandler.IgnoreCyclesorPreserveto hide a cycle. Change the response shape. - Use Newtonsoft.Json.
- Use
[JsonPropertyName]to rename one property. The naming policy names them all.
Check
dotnet test tests/Presentation.Tests.Unit --filter "FullyQualifiedName~Serialization"
dotnet test tests/Presentation.Tests.IntegrationDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

