3

Is there anyway to pass a filestream to System.Text.Json.Utf8JsonReader?

I want to use something like StreamReader as data source so I can scan through files without loading them entirely into memory.

These are the readers constructors

enter image description here

How can I pass this reader a file stream?

For comparison, this is how it is done with the Newtonsoft reader:

using (var stringReader = new StreamReader(@"E:\products.json"))
using (var reader = new JsonTextReader(stringReader))
{
    while (reader.Read())
    {
        if (reader.Value != null)
        {
            Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
        }
        else
        {
            Console.WriteLine("Token: {0}", reader.TokenType);
        }
    }
}

How to do this with new .net core namespace?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Guerrilla
  • 13,375
  • 31
  • 109
  • 210

0 Answers0