ASP.NET Core WebApi Json serialize as PascalCase

6/17/2021

So ASP.NET Core has been out for a few years. My Quid Android phone app is due for an upgrade, starting with the backend REST WebAPI. This is a great time to get started with ASP.NET Core.

Json serialization defaults to pascalCase

To assist with my new Android app, I created a Message project (using .NET Standard), which will be shared between my WebApi app and Android app, with application/json used as the HTTP format. All my message objects use PascalCase.

My initial test revealed the Json showing up in the client was converted to pascalCase. A little searching revealed a simple answer. The following code needed to be added to the ConfigureService call in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers()
        .AddJsonOptions(options =>
        {
            options.JsonSerializerOptions.PropertyNamingPolicy = null;
        });

That's it. Pretty simple fix. Hardly worth a BLOG post. But as with many of my BLOG posts, this one isn't just here for others. It's also for my own reference later...


Please register or login to add a comment.

Comments (displaying 1 - 1):
No comments yet! Be the first...


  • C#/.NET
  • T-SQL
  • HTML/CSS
  • JavaScript/jQuery
  • .NET 8
  • ASP.NET/MVC
  • Xamarin/MAUI
  • WPF
  • Windows 11
  • SQL Server 20xx
  • Android
  • XBox
  • Arduino
  • Skiing
  • Rock Climbing
  • White water kayaking
  • Road Biking