Click or drag to resize
Json.NETJsonPropertyAttribute name
 

This sample uses JsonPropertyAttribute to change the names of properties when they are serialized to JSON.

Sample
Types
1public class Videogame
2{
3    [JsonProperty("name")]
4    public string Name { get; set; }
5
6    [JsonProperty("release_date")]
7    public DateTime ReleaseDate { get; set; }
8}
Usage
 1Videogame starcraft = new Videogame
 2{
 3    Name = "Starcraft",
 4    ReleaseDate = new DateTime(1998, 1, 1)
 5};
 6
 7string json = JsonConvert.SerializeObject(starcraft, Formatting.Indented);
 8
 9Console.WriteLine(json);
10// {
11//   "name": "Starcraft",
12//   "release_date": "1998-01-01T00:00:00"
13// }