How to turn off or handle camelCasing in JSON response ASP.NET Core?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
ASP.NET Core uses System.Text.Json by default, and the default naming policy outputs camelCase property names. If your API contract requires PascalCase or custom naming, you can disable or customize this behavior globally or per endpoint. The right approach depends on compatibility requirements with existing clients.
Core Sections
Default behavior in ASP.NET Core
By default, response JSON usually maps C# properties to camelCase names.
Response may appear as firstName and lastName.
Turn off camel casing globally
Set naming policy to null.
Now JSON keeps original property names such as FirstName.
Per-property overrides
Use attributes when only specific fields need custom names.
This is useful for transitional contracts.
Handling mixed client contracts
If some clients expect camelCase and others expect legacy PascalCase, version your APIs or expose separate endpoints instead of switching naming globally at runtime.
Newtonsoft.Json alternative
If project uses Newtonsoft, equivalent setting is:
Use one serializer stack consistently when possible.
Validation and production readiness
Add contract tests that snapshot response JSON keys. This prevents accidental casing changes during framework upgrades.
Document naming policy in API specifications so client teams do not infer behavior incorrectly. Include migration notices if casing policy changes in a new API version.
Per-endpoint naming policy in Minimal APIs
If you cannot switch casing globally, set options per response. This gives a safe migration path for one endpoint at a time.
This endpoint returns FirstName and LastName while the rest of your API can stay camelCase.
Validate casing with integration tests
Contract tests catch accidental serializer changes after framework upgrades.
Migration strategy for mixed clients
When old and new clients coexist, explicit versioning is cleaner than runtime switching. For example, expose /v1 with PascalCase and /v2 with camelCase, then deprecate gradually. Update OpenAPI documents per version and publish cutoff dates. This avoids hidden behavior and keeps API expectations stable for client teams.
Production checklist and verification loop
A reliable implementation needs more than a working snippet. Add a small verification loop that runs in CI and after dependency upgrades. Start with golden examples that represent normal input, boundary input, and one malformed input. Then validate output values, output shape or schema, and failure messages. This catches silent behavior drift early.
Document assumptions directly in the code comments near the transformation or query logic. Teams often forget whether behavior is strict, permissive, or backward-compatibility focused. Clear assumptions reduce future refactor risk.
For performance-sensitive paths, capture a baseline metric and compare after every change. The metric can be latency, memory use, or throughput depending on workload. Keep benchmark inputs realistic so results are meaningful.
Finally, expose observability signals that tell you when this logic starts failing in production. Useful signals include error counts, validation failures, and rate of fallback paths. A short checklist, a few deterministic tests, and lightweight monitoring are usually enough to keep this solution stable as surrounding systems evolve.
Common Pitfalls
- Changing naming policy without versioning and breaking existing clients.
- Mixing
System.Text.Jsonand Newtonsoft settings unintentionally. - Assuming dictionary keys follow property policy by default.
- Overusing per-property overrides and creating inconsistent contracts.
- Skipping automated contract checks in CI.
Summary
- ASP.NET Core can disable camel casing by setting naming policy to
null. - Use attributes for targeted property name overrides.
- Prefer explicit API versioning when casing contracts differ.
- Keep serializer choice and settings consistent.
- Protect casing expectations with contract tests.
Related reading
- How to turn on front flash light programmatically in Android?
- How to unit test asynchronous APIs?
- How to update a Map or a List on AWS DynamoDB document API?
- How to upload a file and JSON data in Postman?
- How to turn off the logging done by the ASP.NET core framework
- How to upload a file to amazon S3 super easy using c
- How to upload file with python requests?
- How to use Charles Proxy on the Xcode 6 iOS 8 Simulator?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.