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}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s