Ensuring json keys are lowercase in .NET
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If an API contract requires JSON property names such as userid instead of userId or UserId, the built-in defaults in .NET are not enough by themselves. System.Text.Json includes camel case support out of the box, but fully lowercase keys require a custom naming policy.
Lowercase Object Property Names with System.Text.Json
The core mechanism is JsonNamingPolicy. You create a custom policy that converts every property name to lowercase and then assign it through JsonSerializerOptions.PropertyNamingPolicy.
The output is:
That is different from the built-in camel case policy, which would have produced userId and displayName.
Lowercase Dictionary Keys Too
If your payload also contains Dictionary<string, TValue> values, set DictionaryKeyPolicy as well.
This matters because object properties and dictionary keys are handled separately. Configuring one does not automatically configure the other.
ASP.NET Core Global Configuration
In an ASP.NET Core API, you can apply the policy globally:
After that, controller responses use the lowercase naming policy automatically.
Attribute Overrides Still Win
System.Text.Json also supports [JsonPropertyName]. If you apply that attribute, it overrides the naming policy for that property.
That gives you an escape hatch when one field must follow a special external contract.
What About Newtonsoft.Json?
If your project still uses Newtonsoft.Json, the idea is similar, but the configuration point is different. You would typically use a custom NamingStrategy inside a contract resolver. The principle is the same: define the transformation once and apply it centrally rather than renaming properties all over the codebase.
For new ASP.NET Core projects, System.Text.Json is usually the default and should be the first option unless you need a feature that only Newtonsoft provides.
Be Careful with Deserialization Expectations
Property naming policy applies to serialization and deserialization of object property names, but dictionary-key naming policy only affects serialization. That means dictionary keys are not automatically normalized to lowercase when reading JSON back in.
If the inbound contract is also strict, test both directions explicitly rather than assuming symmetry.
Common Pitfalls
The first pitfall is assuming JsonNamingPolicy.CamelCase is lowercase. It is not. It only lowers the initial character according to camel-case rules.
Another pitfall is forgetting dictionary keys. You may serialize object properties in lowercase while nested dictionary keys still come out with their original casing.
A third pitfall is using [JsonPropertyName] in a few places and then wondering why those members ignore the global policy. The attribute has higher precedence.
Finally, consider API compatibility. Changing key casing is a contract change and can break existing clients, so do it deliberately.
Summary
- Fully lowercase JSON keys in .NET require a custom
JsonNamingPolicy - Set
PropertyNamingPolicyfor object properties andDictionaryKeyPolicyfor dictionary keys - In ASP.NET Core, configure the policy once through
AddJsonOptions - '
[JsonPropertyName]overrides the global naming policy' - Do not confuse camel case with fully lowercase output
Related reading
- Enter key press in C
- Enter symbol into a text Label in Windows Forms?
- Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type
- Entity Framework - Code First - Can't Store ListString
- Entity Framework - Invalid Column Name '_ID when not using entity connection string
- Entity Framework 4 - AddObject vs Attach
- Entity Framework 4 mapping fragment error when adding new entity scalar
- Entity Framework 4 Single vs First vs FirstOrDefault

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.