title: MVC JsonResult camelCase serialization
body: <p>I am trying to make my action return a JsonResult where all its properties are in camelCase. </p>
  
  <p>I have a simply model:</p>
  
  <pre><code>public class MyModel
  {
      public int SomeInteger { get; set; }
  
      public string SomeString { get; set; }
  }
  </code></pre>
  
  <p>And a simple controller action:</p>
  
  <pre><code>public JsonResult Index()
      {
          MyModel model = new MyModel();
          model.SomeInteger = 1;
          model.SomeString = "SomeString";
  
          return Json(model, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>Calling this action method now returns a JsonResult containing the following data:</p>
  
  <pre><code>{"SomeInteger":1,"SomeString":"SomeString"}
  </code></pre>
  
  <p>For my uses i need the action return the data in camelCase, somehow like this:</p>
  
  <pre><code>{"someInteger":1,"someString":"SomeString"}
  </code></pre>
  
  <p>Is there any elegant way to do this?</p>
  
  <p>I was looking into possible solutions around here and found <a href="https://stackoverflow.com/questions/7260924/mvc3-json-serialization-how-to-control-the-property-names">MVC3 JSON Serialization: How to control the property names?</a> where they set DataMember definitions to every property of the model, but I do not really want to do this. </p>
  
  <p>Also I found a link where they say that it is possible to solve exactly this kind of issue: <a href="http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#json_camelcasing" rel="noreferrer">http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#json_camelcasing</a>. It says: </p>
  
  <p><strong>To write JSON property names with camel casing, without changing your data model, set the CamelCasePropertyNamesContractResolver on the serializer:</strong></p>
  
  <pre><code>var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
  json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
  </code></pre>
  
  <p>One entry on this blog <a href="http://frankapi.wordpress.com/2012/09/09/going-camelcase-in-asp-net-mvc-web-api/" rel="noreferrer">http://frankapi.wordpress.com/2012/09/09/going-camelcase-in-asp-net-mvc-web-api/</a> also mentiones this solution and states you can simply add it to the <strong>RouteConfig.RegisterRoutes</strong> to fix this issue. I tried it, but I couldn't make it work.</p>
  
  <p>Do you guys have any idea where I was doing something wrong?</p>