Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 1.23 KB

JsonPropertyName.md

File metadata and controls

36 lines (30 loc) · 1.23 KB

JsonPropertyAttribute name

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

public class Videogame
{
    [JsonProperty("name")] public string Name { get; set; }

    [JsonProperty("release_date")] public DateTime ReleaseDate { get; set; }
}

snippet source | anchor

var starcraft = new Videogame
{
    Name = "Starcraft",
    ReleaseDate = new(1998, 1, 1)
};

var json = JsonConvert.SerializeObject(starcraft, Formatting.Indented);

Console.WriteLine(json);
// {
//   "name": "Starcraft",
//   "release_date": "1998-01-01T00:00:00"
// }

snippet source | anchor