Click or drag to resize
Json.NET

JsonPropertyAttribute property setting

 

This sample uses JsonPropertyAttribute to change how the property value is serialized.

Sample
Types
public class Vessel
{
    public string Name { get; set; }
    public string Class { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public DateTime? LaunchDate { get; set; }
}
Usage
Vessel vessel = new Vessel
{
    Name = "Red October",
    Class = "Typhoon"
};

string json = JsonConvert.SerializeObject(vessel, Formatting.Indented);

Console.WriteLine(json);
// {
//   "Name": "Red October",
//   "Class": "Typhoon"
// }