Click or drag to resize
Json.NETJsonPropertyAttribute required
 

This sample uses JsonPropertyAttribute to set Required which is used during deserialization to validate the presence of required JSON properties.

Sample
Types
1public class Videogame
2{
3    [JsonProperty(Required = Required.Always)]
4    public string Name { get; set; }
5
6    [JsonProperty(Required = Required.AllowNull)]
7    public DateTime? ReleaseDate { get; set; }
8}
Usage
 1string json = @"{
 2  'Name': 'Starcraft III',
 3  'ReleaseDate': null
 4}";
 5
 6Videogame starcraft = JsonConvert.DeserializeObject<Videogame>(json);
 7
 8Console.WriteLine(starcraft.Name);
 9// Starcraft III
10
11Console.WriteLine(starcraft.ReleaseDate);
12// null