Tuesday, June 10, 2014

ASP.NET Web API: use camel casing for your JSON objects

There is a general agreement to use PascalCasing for your objects in .NET, this in contrast to JavaScript where camelCasing is the default.  This is a little bit unfortunate when you are using ASP.NET Web API and want to return a JSON object to your JavaScript object. By default the properties will be PascalCased because of the fact that your C# objects are PascalCased as well.

Luckily this is an easy one to fix using the Json.NET serializer. Inside the WebAPIConfig class, add the following lines:

No comments: