Configure NamingStrategy property name serialization |
This sample configures a CamelCaseNamingStrategy to not camel case properties that already have a name specified with an attribute.
public class User { public string FirstName { get; set; } public string LastName { get; set; } [JsonProperty(PropertyName = "UPN")] public string Upn { get; set; } }
User user = new User { FirstName = "John", LastName = "Smith", Upn = "john.smith@acme.com" }; DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy { OverrideSpecifiedNames = false } }; string json = JsonConvert.SerializeObject(user, new JsonSerializerSettings { ContractResolver = contractResolver, Formatting = Formatting.Indented }); Console.WriteLine(json); // { // "firstName": "John", // "lastName": "Smith", // "UPN": "john.smith@acme.com" // }