Last Updated: February 25, 2016
·
442
· oleggavrilov

camelCasing JSON in ASP.NET WebAPI

Simple. In global.asax (or somewhere you define your formatters) use this:

var formatters = GlobalConfiguration.Configuration.Formatters;
var jsonFormatter = formatters.JsonFormatter;
var settings = jsonFormatter.SerializerSettings;
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();

This only works with default json formatter (JSON.NET), but im sure all other libraries have something similiar.