Serialize JSON
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
string json = JsonConvert.SerializeObject(product);
Deserialize JSON
string json = @"{
‘Name‘: ‘Bad Boys‘,
‘ReleaseDate‘: ‘1995-4-7T00:00:00‘,
‘Genres‘: [
‘Action‘,
‘Comedy‘
]
}";
Movie m = JsonConvert.DeserializeObject<Movie>(json);
string name = m.Name;
Validate JSON
JsonSchema schema = JsonSchema.Parse(@"{
‘type‘: ‘object‘,
‘properties‘: {
‘name‘: {‘type‘:‘string‘},
‘hobbies‘: {‘type‘: ‘array‘}
}
}");
JObject person = JObject.Parse(@"{
‘name‘: ‘James‘,
‘hobbies‘: [‘.NET‘, ‘LOLCATS‘]
}");
bool valid = person.IsValid(schema);
Json.NET