asp.net core 1.0 web api use camelcase

Brivvirs picture Brivvirs · Jul 1, 2016 · Viewed 22.9k times · Source

On RC2 the same code returns json format with camel case. After netcore 1.0 release i started new project and the same code is returning json in lowercase.

Tried multiple solutions but none of them were working web-api-serialize-properties-starting-from-lowercase-letter

Answer

Brivvirs picture Brivvirs · Jul 1, 2016
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.