Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analogous Newtonsoft JsonReader/JsonTextReader in System.Text.Json

Does the .NET provided System.Text.Json namespace provide an analogous service/class to Newtonsoft.Json's JsonReader/JsonTextReader?

Our new app has been built using only System.Text.Json dependencies but we now have a requirement to process extremely large JSON files (10's of GBs). This require us to read the files as a Stream sequentially as opposed to loading the entire objects into memory.

We were able to hook this up using Newtonsoft.Json's JsonReader/JsonTextReader but was wondering if this same functionality existed without using this external dependency and mixing Json libraries.

using (StreamReader sr = new(stream))
using (JsonReader jsonReader = new JsonTextReader(sr))
{
    while (jsonReader.Read())
    {
        // Do Work
    }
}     
like image 600
smk081 Avatar asked Dec 06 '25 18:12

smk081


1 Answers

The System.Text.Json namespace provides the Utf8JsonReader class, which is analogous to JsonReader/JsonTextReader from Newtonsoft.Json.

Migrate from Newtonsoft.Json to System.Text.Json

like image 58
Akli Avatar answered Dec 08 '25 07:12

Akli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!