Skip to content

Latest commit

 

History

History
44 lines (38 loc) · 1.38 KB

NamingStrategySnakeCase.md

File metadata and controls

44 lines (38 loc) · 1.38 KB

Snake case property names

This sample uses a Argon.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; }
}

snippet source | anchor

var user1 = new User
{
    UserName = "jamesn",
    Enabled = true
};

var contractResolver = new DefaultContractResolver
{
    NamingStrategy = new SnakeCaseNamingStrategy()
};

var json = JsonConvert.SerializeObject(user1, new JsonSerializerSettings
{
    ContractResolver = contractResolver,
    Formatting = Formatting.Indented
});

Console.WriteLine(json);
// {
//   "user_name": "jamesn",
//   "enabled": true
// }

snippet source | anchor