In this article I will explain with an example, how to change the default
Camel Case JSON Output in ASP.Net Core (.Net Core 3).
Need to change the JSON Serializer setting
The ASP.Net Core (.Net Core 3)
AJAX program will work, but you will see
undefined values in the
JavaScript Alert Message Box (as shown below) when you try to parse the
JSON.
Configuring JSON Serializer setting
Inside the ConfigureServices method of Startup.cs class, the AddJsonOptions method of the services object is called where the PropertyNamingPolicy is set to NULL.
This will remove the default
Camel Case naming policy and
JSON property names will remain intact as defined in the classes.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
}
Other available versions