Click or drag to resize
Json.NETSnake case property names
 

This sample uses a SnakeCaseNamingStrategy specified using a contract resolver to snake case serialized property names.

Sample
Types
1public class User
2{
3    public string UserName { get; set; }
4    public bool Enabled { get; set; }
5}
Usage
 1User user1 = new User
 2{
 3    UserName = "jamesn",
 4    Enabled = true
 5};
 6
 7DefaultContractResolver contractResolver = new DefaultContractResolver
 8{
 9    NamingStrategy = new SnakeCaseNamingStrategy()
10};
11
12string json = JsonConvert.SerializeObject(user1, new JsonSerializerSettings
13{
14    ContractResolver = contractResolver,
15    Formatting = Formatting.Indented
16});
17
18Console.WriteLine(json);
19// {
20//   "user_name": "jamesn",
21//   "enabled": true
22// }