Click or drag to resize
Json.NETConfigure NamingStrategy property name serialization
 

This sample configures a CamelCaseNamingStrategy to not camel case properties that already have a name specified with an attribute.

Sample
Types
1public class User
2{
3    public string FirstName { get; set; }
4    public string LastName { get; set; }
5    [JsonProperty(PropertyName = "UPN")]
6    public string Upn { get; set; }
7}
Usage
 1User user = new User
 2{
 3    FirstName = "John",
 4    LastName = "Smith",
 5    Upn = "john.smith@acme.com"
 6};
 7
 8DefaultContractResolver contractResolver = new DefaultContractResolver
 9{
10    NamingStrategy = new CamelCaseNamingStrategy
11    {
12        OverrideSpecifiedNames = false
13    }
14};
15
16string json = JsonConvert.SerializeObject(user, new JsonSerializerSettings
17{
18    ContractResolver = contractResolver,
19    Formatting = Formatting.Indented
20});
21
22Console.WriteLine(json);
23// {
24//   "firstName": "John",
25//   "lastName": "Smith",
26//   "UPN": "john.smith@acme.com"
27// }