This sample serializes an object to JSON without any formatting or indentation whitespace.
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 =
[
"User",
"Admin"
]
};
var json = JsonConvert.SerializeObject(account);
// {"Email":"[email protected]","Active":true,"CreatedDate":"2013-01-20T00:00:00Z","Roles":["User","Admin"]}
Console.WriteLine(json);