अंग्रेज़ी में पढ़ें संपादित करें

इसके माध्यम से साझा किया गया


How to enable case-insensitive property name matching with System.Text.Json

In this article, you learn how to enable case-insensitive property name matching with the System.Text.Json namespace.

Case-insensitive property matching

By default, deserialization looks for case-sensitive property name matches between JSON and the target object properties. To change that behavior, set JsonSerializerOptions.PropertyNameCaseInsensitive to true:

नोट

The web default is case-insensitive.

var options = new JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true
};
WeatherForecast? weatherForecast = JsonSerializer.Deserialize<WeatherForecast>(jsonString, options);

Here's example JSON with camel case property names. It can be deserialized into the following type that has Pascal case property names.

{
  "date": "2019-08-01T00:00:00-07:00",
  "temperatureCelsius": 25,
  "summary": "Hot",
}
public class WeatherForecast
{
    public DateTimeOffset Date { get; set; }
    public int TemperatureCelsius { get; set; }
    public string? Summary { get; set; }
}

See also