using System.Text.Json.Serialization;
""name"": ""Luke Skywalker"",
""birth_year"": ""19BBY"",
var options = new JsonSerializerOptions()
{PropertyNameCaseInsensitive = true, NumberHandling = JsonNumberHandling.AllowReadingFromString, Converters = {new BirthYearConverter(), }};
var deserialize = JsonSerializer.Deserialize<Character[]>(json, options);
Console.WriteLine(deserialize[0].Weight);
public string Name { get; init; } = "";
[property: JsonPropertyName("birth_year")]
public double Birth { get; init; }
public int Height { get; init; }
[property: JsonPropertyName("mass")]
public int Weight { get; init; }
class BirthYearConverter : JsonConverter<double>
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
return double.TryParse(reader.GetString()?.TrimEnd('B', 'b', 'Y', 'y'), out double result) ? result : 0;
public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
throw new NotImplementedException();