JsonObjectAttribute NamingStrategy setting |
This sample uses NamingStrategy types specified on attributes to control serialized property names.
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class User { public string FirstName { get; set; } public string LastName { get; set; } [JsonProperty(NamingStrategyType = typeof(SnakeCaseNamingStrategy))] public int SnakeRating { get; set; } }
User user = new User { FirstName = "Tom", LastName = "Riddle", SnakeRating = 10 }; string json = JsonConvert.SerializeObject(user, Formatting.Indented); Console.WriteLine(json); // { // "firstName": "Tom", // "lastName": "Riddle", // "snake_rating": 10 // }