title: Proper JSON serialization in MVC 4
body: <p>I'd like to have JSON 'properly' serialized (camelCase), and the ability to change date formats if necessary. </p>
  
  <p>For Web API it is very easy - in the Global.asax I execute the following code</p>
  
  <pre><code>var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
  json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
  </code></pre>
  
  <p>This code, at the pipeline level, handles serialization the way I'd like. </p>
  
  <p>I would like to accomplish the same thing in MVC 4 - have any JSON returned from controller action methods to be serialized properly.  With a little searching I found the following code to throw in the Global.asax application startup:</p>
  
  <pre><code>HttpConfiguration config = GlobalConfiguration.Configuration;
  Int32 index = config.Formatters.IndexOf(config.Formatters.JsonFormatter);
  config.Formatters[index] = new JsonMediaTypeFormatter
  {
       SerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
  };
  </code></pre>
  
  <p>It seems to execute fine but when I return JSON from a controller it is all PascalCased.  A simple example of my action method:</p>
  
  <pre><code>private JsonResult GetJsonTest()
  {
      var returnData = dataLayer.GetSomeObject();
      return Json(returnData, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>Am I going about this wrong? Any idea how to accomplish this at the pipeline level?</p>