The default JsonSerializerOptions
values for web apps is case-insensitive.
Taken from these docs (see the note):
By default, deserialization looks for case-sensitive property name
matches between JSON and the target object properties. To change that
behavior, set JsonSerializerOptions.PropertyNameCaseInsensitive to
true:
Note
The web default is case-insensitive.
You want to configure the serializer to use PropertyNameCaseInsensitive = false
in order to be case-sensitive.
You can configure the options in ConfigureServices
method in Startup.cs
:
services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = false;
});
or in .NET 6 using minimal API:
builder.Services.Configure<JsonOptions>(options =>
{
options.SerializerOptions.PropertyNameCaseInsensitive = false;
});