JSON casing in ASP.NET Core

Some mallethead decided that they wanted to take UpperCamelCase names of properties and change them to lowerCamelCase when sending JSON to the client. Sure, maybe this fits standard naming conventions, but it means that you’ll end up with different property names.

public JsonResult GetFoo()
    return Json(new Foo { 
        Name = "Jane Doe", 
        Age = 32 

This returns the following content:

{"name":"Jane Doe","age":32}

Personally, I want the properties to match. Here’s the change to make that happen:

// dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson
// Startup.cs: in ConfigureServices
services.AddNewtonsoftJson(options =>

Now the same code produces:

{"Name":"Jane Doe","Age":32}


Popular posts from this blog

DotNet CLI

Switch Expressions