Newtonsoft JsonSerializer - Lower case properties and dictionary [duplicate]

You could try using the CamelCasePropertyNamesContractResolver.

var serializerSettings = new JsonSerializerSettings();
serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
var json = JsonConvert.SerializeObject(product, serializerSettings);

I'm just not sure how it'll handle the dictionary keys and I don't have time right this second to try it. If it doesn't handle the keys correctly it's still worth keeping in mind for the future rather than writing your own custom JSON writer.


You can use a JsonProperty to change how something is serialized/deserialized. When you define your object add the property items to the fields you would like represented differently in the JSON. This only works with NewtonsoftJSON. Other libraries may do it differently.

public class Product
{
    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("items")]
    public Dictionary<string, Item> Items { get; set; }
}

public class Item
{
    [JsonProperty("description")]
    public string Description { get; set; }
}