my goal is to use System.text.Json
to parse a response from the rest api.
The response returns one or more items - but if only one item is returned, there are no brackets []
surrounding it (which makes it hard to parse).
The deserialization:
// i need a list here to process data
var response = JsonSeralizer.Deseralize<IList<ExampleResponse>>(content);
Example response 1:
[
{
"Status": "Healthy"
},
{
"Status": "Healthy"
}
]
Example response 2:
{
"Status": "Healthy"
}
How can i write a custom converter using JsonConverter<T>
, which can parse a single item or an entire list?