I want all JSON responses to use camel case, and tried below code, but it is not working and response is still in Pascal case. I also tried setting [JsonPropertyName("myCamelCaseProperty")]
to override, but response still is in Pascal case.
Any suggestions how camel case can be made as default for all responses (all properties)?
builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options =>
{
options.SerializerOptions.PropertyNameCaseInsensitive = false;
options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
2
Answers
By Default .Net 6 gives response in Camel Case. Here is the screen shot of my model and response.
Response:
In startup.cs :
Then install
Microsoft.AspNetCore.Mvc.NewtonsoftJson
In you class reference above using
[JsonProperty("customName")]