Click or drag to resize
Json.NETJsonPropertyAttribute order
 

This sample uses JsonPropertyAttribute to order of properties when they are serialized to JSON.

Sample
Types
 1public class Account
 2{
 3    public string EmailAddress { get; set; }
 4
 5    // appear last
 6    [JsonProperty(Order = 1)]
 7    public bool Deleted { get; set; }
 8
 9    [JsonProperty(Order = 2)]
10    public DateTime DeletedDate { get; set; }
11
12    public DateTime CreatedDate { get; set; }
13    public DateTime UpdatedDate { get; set; }
14
15    // appear first
16    [JsonProperty(Order = -2)]
17    public string FullName { get; set; }
18}
Usage
 1Account account = new Account
 2{
 3    FullName = "Aaron Account",
 4    EmailAddress = "aaron@example.com",
 5    Deleted = true,
 6    DeletedDate = new DateTime(2013, 1, 25),
 7    UpdatedDate = new DateTime(2013, 1, 25),
 8    CreatedDate = new DateTime(2010, 10, 1)
 9};
10
11string json = JsonConvert.SerializeObject(account, Formatting.Indented);
12
13Console.WriteLine(json);
14// {
15//   "FullName": "Aaron Account",
16//   "EmailAddress": "aaron@example.com",
17//   "CreatedDate": "2010-10-01T00:00:00",
18//   "UpdatedDate": "2013-01-25T00:00:00",
19//   "Deleted": true,
20//   "DeletedDate": "2013-01-25T00:00:00"
21// }