using System.Text.Json; using System.Text.Json.Serialization; public class JsonStringBooleanConverter : JsonConverter { public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var val = reader.GetString(); if (val == "true") return true; if (val == "false") return false; throw new Exception($"Cannot convert {val} to boolean"); } public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) { writer.WriteBooleanValue(value); } }