using Newtonsoft.Json.Serialization;
public static void Main()
var product = new Product() { ProductId = 1, Name = "MyProduct", UnitPrice = 10.00M };
var serialised = JsonConvert.SerializeObject(product);
Console.WriteLine(serialised);
var settings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() };
serialised = JsonConvert.SerializeObject(product, settings);
Console.WriteLine(serialised);
settings = new JsonSerializerSettings() { ContractResolver = new LowerCasePropertyNamesContractResolver() };
serialised = JsonConvert.SerializeObject(product, settings);
Console.WriteLine(serialised);
var product2 = new Product2() { ProductId = 2, Name = "My Another Product", UnitPrice = 20.00M };
serialised = JsonConvert.SerializeObject(product2, settings);
Console.WriteLine(serialised);
public int ProductId { get; set; }
public string Name { get; set; }
public decimal UnitPrice { get; set; }
[JsonProperty(PropertyName = "Product_Id")]
public int ProductId { get; set; }
[JsonProperty(PropertyName = "Product.Name")]
public string Name { get; set; }
public decimal UnitPrice { get; set; }
public class LowerCasePropertyNamesContractResolver : DefaultContractResolver
protected override string ResolvePropertyName(string propertyName)
return propertyName.ToLower();