I expected this code to throw an Exception because I am trying to deserialize a string value into a boolean property. However, I was surprised to find that Json.NET happily converts the string value to a boolean. Why? Is there any way to change this behavior, for example a "strict" mode?
using Newtonsoft.Json;
var activeAccount = JsonConvert.DeserializeObject<Account>("{\"active\": \"True\"}");
var inactiveAccount = JsonConvert.DeserializeObject<Account>("{\"active\": \"false\"}");
Console.WriteLine(activeAccount.Active); // True
Console.WriteLine(inactiveAccount.Active); // False
public class Account
{
public bool Active { get; set; }
}