✅ How to serialize IEnumerable<T> to json?
I have following:
and I want to get following:
"
{
"Key": "GetValueBytes()",
...
}
"
how can I do it?
and I want to get following:
"
{
"Key": "GetValueBytes()",
...
}
"
how can I do it?
byte[] will result in a base64 encoded string,Headers as
hm maybe I can do smth like.. 
IEnumerable<byte>IReadOnlyDictionary<string, byte[]>"header1": "base64-encoded-byte-array""header1": "1,254,4,6,127"public static class MessageQueueConsumeResultHeaderExtensions
{
public static string ToJson(this IReadOnlyList<MessageQueueConsumeResultHeader>? headers)
{
if (headers == null || headers.Count == 0)
{
return "{}";
}
var result = new StringBuilder();
result.AppendLine("{");
foreach (var header in headers)
{
result.AppendLine($" \"{header.Key}\": \"{string.Join(",", header.GetValueBytes())}\",");
}
result.Length--; // Remove the trailing comma
result.AppendLine("}");
return result.ToString();
}
}var map = context.Headers?.ToDictionary(x => x.Key, x => x.GetValueBytes());
var result = JsonSerializer.Serialize(map);