ASP.NET ViewModels typically follow the C# convention of Pascal casing property names. By default, the Json serializer spits out Json objects with field names matching the property names. In JavaScript, it is conventional to use camel casing for almost everything – if something starts with a capital letter and is not all caps, then it denotes that new must be used to instantiate an instance. Not using new in this case causes weird problems, so the capital letter at the start serves as a mechanism to make this immediately visible.

There are ways to get ASP.NET MVC / WebApi to spit out camel cased Json object. This usually revolves around setting a format globally. However, when working with apps that are currently sending out wrongly cased Json, making a global change to flip the switch may be quite difficult, as who knows what’ll break. For these scenarios, it is better to configure settings like these on a more granular level. Enter IControllerConfiguration.

All you have to do is write an attribute that looks like the following:

With this in place, we can decorate any of our controllers with [CamelCasedJson], and it will output camel cased json output. This can be useful to gradually fix those Pasccal-cased-Json emitting controllers, or add newer functionality without having to keep on using broken conventions because other existing parts do it that way. One thing to note is that the model binders aren’t case sensitive. So whether you POST camel cased or Pascal cased JSon to the controller, you don’t need to take any additional measures. And of course, it’s not just Json serialisation format – you have access to a whole host of settings that you can set within that attribute or a per controller basis.

Hope that helps :)