Reading Async JSON as stream

Knowing that the dataset coming back may be large and will take time to receive as well as decoding the each element as it is parsed from the stream to reduce cpu and memory load

Helpful generic HttpClient extension class

public static class HttpClientExtensions
{
	private static IEnumerable<T> Read<T>(JsonReader reader) where T : class, new()
	{
		var items = new List<T>();
		reader.SupportMultipleContent = true;
		var serializer = new JsonSerializer();
		while (reader.Read())
		{
		if (reader.TokenType != JsonToken.StartObject) { continue; }
		items.Add(serializer.Deserialize<T>(reader));
		}
		return items;
	}

	public static async Task<IEnumerable<T>> GetDataAsync<T>(this HttpClient current, string orderUrl) where T : class, new()
	{
		using (var stream = await current.GetStreamAsync(orderUrl))
		using (var streamReader = new StreamReader(stream))
		using (var reader = new JsonTextReader(streamReader))
		{
			return Read<T>(reader);
		}
	}
}

Example

https://gist.github.com/Siliconrob/6877a325014208c7eff67829c350aed2