I need to deserialize dynamic JSON text that can represent either System.Collections.Generic.Dictionary<string, T> or System.Collections.Generic.List< T>. I suppose I have to write custom converter but I'm not sure about how it should look like properly. I'm using .NET5's System.Text.Json.
Sample JSON for dictionary type (sent almost all the time):
{
"1":
{
"13346964555":
{
"data1":1,
"data2":2
},
"13346964556":
{
"data1":1,
"data2":2
},
}
}
Sample JSON for list type (rare, needs to be converted into dictionary with empty string keys):
{
"1": [
{
"data1":1,
"data2":2
},
{
"data1":1,
"data2":2
}
]
}
On the other side, converting from normal dictionary to list of its values is acceptable as well, since I don't need keys at all currently.