Click or drag to resize
Json.NETJsonPropertyAttribute property setting
 

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

Sample
Types
1public class Vessel
2{
3    public string Name { get; set; }
4    public string Class { get; set; }
5
6    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
7    public DateTime? LaunchDate { get; set; }
8}
Usage
 1Vessel vessel = new Vessel
 2{
 3    Name = "Red October",
 4    Class = "Typhoon"
 5};
 6
 7string json = JsonConvert.SerializeObject(vessel, Formatting.Indented);
 8
 9Console.WriteLine(json);
10// {
11//   "Name": "Red October",
12//   "Class": "Typhoon"
13// }