asp.net core 1.0 web api use camelcase
services .AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); });
This keeps a JSON object's name the same as .NET class property.
You can configure JSON behavior this way:
public void ConfigureServices(IServiceCollection services) { services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); }
You can also do this at the individual serializer level, instead of at the global level.
For example, to return an object as JSON on a controller action method you can do this:
var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() };return new JsonResult(myObject, jsonSerializerSettings);
And the resulting JSON string will be in the expected PascalCase to match the .NET class/properties names