Snake case property names |
This sample uses a SnakeCaseNamingStrategy specified using a contract resolver to snake case serialized property names.
public class User { public string UserName { get; set; } public bool Enabled { get; set; } }
User user1 = new User { UserName = "jamesn", Enabled = true }; DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }; string json = JsonConvert.SerializeObject(user1, new JsonSerializerSettings { ContractResolver = contractResolver, Formatting = Formatting.Indented }); Console.WriteLine(json); // { // "user_name": "jamesn", // "enabled": true // }