System.Text.JSON doesn't deserialize what Newtonsoft does System.Text.JSON doesn't deserialize what Newtonsoft does json json

System.Text.JSON doesn't deserialize what Newtonsoft does


The default behavior of the System.Text.Json deserializer is to match properties as case sensitive. You need to pass options telling it to match case insensitive:

using System.Text.Json;JsonSerializer.Deserialize<T>(json_data, new JsonSerializerOptions {    PropertyNameCaseInsensitive = true});


For setting globally, in startup.cs set

    services.AddControllers(options =>    {    }).AddJsonOptions(options =>    {        options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;        options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Default;    });


if (response.IsSuccessStatusCode){   var json = await response.Content.ReadAsStringAsync();   var options = new JsonSerializerOptions   {       WriteIndented = true,       PropertyNameCaseInsensitive = true // this is the point   };   var books = JsonSerializer.Deserialize<IEnumerable<Book>>(json, options);}