System.Text.Json asynchronous streaming deserialization support #29906
Labels
area-System.Text.Json
json-functionality-doc
Missing JSON specific functionality that needs documenting
Milestone
Hello team,
We've been eager to try the new
System.Text.Json
APIs for their native UTF8 support, but it seems based off the preview release announcement and the API exposed by the current preview release of theSystem.Text.Json
that there's a lack of streaming support, i.e. reading individual JSON tokens without first having the entire document loaded into memory (and then parsed as aJsonDocument
).The Newtonsoft JSON library had a
JsonTextReader
that could lazily consume an underlyingStream
and return a token at a time viaJsonTextReader.ReadAsync(..)
, which moved the document cursor/pointer to the next node in the stream. It had some shortcomings (it couldn't skip past a nested node, you had to step through it IIRC) but it served the purpose of being able to navigate asynchronously to a particular node in a JSON document and then selectively parse its value without having to first buffer the entire stream beforehand or to parse the entirety of the document in order to enumerate its nodes.I assumed that
Utf8JsonReader
would for sure do the same thing, but it seems that aUtf8JsonReader
can only be created on top of an availableReadOnlySequence<T>
and all its methods are blocking.JsonDocument
can be created on top of aStream
and does not appear to consume the entire stream upon initialization, but only offers aParseAsync()
method that asynchronously reads from the underlying stream; except it consumes the entirety of the stream and loads the entire document into memory.I'm probably missing something, but is there no way to asynchronously and lazily navigate a UTF8 JSON stream, without buffering the entire document in memory and without blocking unnecessarily for IO?
The text was updated successfully, but these errors were encountered: