Eine List<ChatMsg> ist in JSON automatisch ein JSON-Array. Du brauchst also nur ein Container Objekt drum herum. Am besten baust du dir dazu eine Wrapper Klasse
using System.Text.Json;
using System.Text.Json.Serialization;
public sealed class ChatLog
{
[JsonPropertyName("messages")]
public List<ChatMsg> Messages { get; set; } = new();
}dann kannst du es ganz einfach serialisieren.
List<ChatMsg> list = /* deine Liste */;
var log = new ChatLog { Messages = list };
var options = new JsonSerializerOptions
{
WriteIndented = true, // formatiert
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
string json = JsonSerializer.Serialize(log, options);