using Newtonsoft.Json.Serialization;
public static void Main()
var myClass = new MyClass
AnotherName = "pineapple",
AnotherValue = "not as delicious as the apple"
var settings = new JsonSerializerSettings
ContractResolver = new CustomResolver(),
Formatting = Formatting.Indented
var json = JsonConvert.SerializeObject(myClass, settings);
[MyCustomProperty("name")]
public string SomeName { get; set; }
[MyCustomProperty("value")]
public string SomeValue { get; set; }
public string AnotherName { get; set; }
public string AnotherValue { get; set; }
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class MyCustomPropertyAttribute : Attribute
public string PropertyName { get; set; }
public MyCustomPropertyAttribute(string propertyName)
PropertyName = propertyName;
public class CustomResolver : DefaultContractResolver
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
JsonProperty property = base.CreateProperty(member, memberSerialization);
MyCustomPropertyAttribute customAttribute = (MyCustomPropertyAttribute)property.AttributeProvider.GetAttributes(typeof(MyCustomPropertyAttribute), true).FirstOrDefault();
if (customAttribute != null)
property.PropertyName = customAttribute.PropertyName;