This sample serializes an object to JSON.
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
var account = new Account
{
Email = "[email protected]",
Active = true,
CreatedDate = new(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
Roles = new List<string>
{
"User",
"Admin"
}
};
var json = JsonConvert.SerializeObject(account, Formatting.Indented);
// {
// "Email": "[email protected]",
// "Active": true,
// "CreatedDate": "2013-01-20T00:00:00Z",
// "Roles": [
// "User",
// "Admin"
// ]
// }
Console.WriteLine(json);