0 Comments

When starting a new ASP.NET project there is  a folder called App_Start and inside this folder you will find a file WebApiConfig. This file should be used for all config for any ApiController. It already contains some element of configuration, but it is missing one very important (IMO): the camelCasing of the properties of a JSON response. When making a call to an ApiController without the camel case settings the JSON response will be like so :

preCamelCase

As you can see from the response (lower box) all the properties name start with a capital letter, which could cause problems when users would want to use your API, or when mapping with a Javascript library. By adding a single line of code in the Register methood of the WebApiConfig.cs file:

config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
 

Your JSON response will now return what is considered to be valid JSON :

postCamelCase