Utf8JsonAsyncStreamReader 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Utf8JsonAsyncStreamReader --version 1.2.0
                    
NuGet\Install-Package Utf8JsonAsyncStreamReader -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Utf8JsonAsyncStreamReader" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Utf8JsonAsyncStreamReader" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Utf8JsonAsyncStreamReader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Utf8JsonAsyncStreamReader --version 1.2.0
                    
#r "nuget: Utf8JsonAsyncStreamReader, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Utf8JsonAsyncStreamReader@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Utf8JsonAsyncStreamReader&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Utf8JsonAsyncStreamReader&version=1.2.0
                    
Install as a Cake Tool

Utf8JsonAsyncStreamReader

NuGet Version NuGet Downloads

Overview

An asynchronous forward-only streaming JSON parser and deserializer based on System.Text.Json.Utf8JsonReader. This library enables efficient processing of large JSON streams with minimal memory usage by buffering stream reads and supporting conditional branch deserialization. Memory consumption is optimized based on either the buffer size used or the specific JSON property branch being deserialized.

Perfect for scenarios involving:

  • Large JSON file processing
  • Web API streaming responses
  • Memory-constrained environments
  • Real-time data processing

Getting Started

Installation

Install the package via NuGet Package Manager:

<PackageReference Include="Utf8JsonAsyncStreamReader" Version="1.2.0" />

Or via the Package Manager Console:

Install-Package Utf8JsonAsyncStreamReader

Or via the .NET CLI:

dotnet add package Utf8JsonAsyncStreamReader

Requirements

  • .NET 7.0, .NET 8.0, or .NET 9.0
  • System.IO.Pipelines (automatically included)

Usage

Basic Stream Reading

using System.Text.Json.Stream;

// Create a stream (file, HTTP response, etc.)
using var fileStream = File.OpenRead("large-data.json");
using var reader = new Utf8JsonAsyncStreamReader(fileStream);

// Read JSON tokens asynchronously
while (await reader.ReadAsync())
{
    switch (reader.TokenType)
    {
        case JsonTokenType.PropertyName:
            Console.WriteLine($"Property: {reader.Value}");
            break;
        case JsonTokenType.String:
            Console.WriteLine($"String Value: {reader.Value}");
            break;
        case JsonTokenType.Number:
            Console.WriteLine($"Number Value: {reader.Value}");
            break;
        // Handle other token types...
    }
}

Object Deserialization

using System.Text.Json.Stream;

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    public string Email { get; set; }
}

// Deserialize directly from stream
using var stream = GetJsonStream(); // Your JSON stream source
using var reader = new Utf8JsonAsyncStreamReader(stream);

var person = await reader.DeserializeAsync<Person>();
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");

Custom JsonSerializerOptions

var options = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    PropertyNameCaseInsensitive = true
};

using var reader = new Utf8JsonAsyncStreamReader(stream);
var result = await reader.DeserializeAsync<MyObject>(options);

Processing Large Collections

// For large JSON arrays, process items one by one
using var reader = new Utf8JsonAsyncStreamReader(stream);

await reader.ReadAsync(); // StartArray
while (await reader.ReadAsync() && reader.TokenType != JsonTokenType.EndArray)
{
    var item = await reader.DeserializeAsync<MyItem>();
    ProcessItem(item); // Process each item individually
}

Samples

Explore these comprehensive examples and tutorials:

These resources include:

  • Full working samples
  • Performance benchmarks
  • Memory usage comparisons
  • File and web streaming examples
  • Support for compressed (zipped) files
  • Handling very large datasets

Support

If you find this library useful, please consider buying me a coffee ☕.

History

V1.2.0 - December 2024

  • Added .NET 9.0 support
  • Added symbols support to NuGet package
  • Updated readme with improved documentation
  • Enhanced test coverage for all target frameworks

V1.1.0 - Previous Release

  • Updated to support .NET 8.0
  • Fixed missing parameter JsonSerializerOptions in one call

V1.0.0 - Initial Release

  • Initial release with .NET 7.0 support
  • Core streaming JSON functionality
  • Basic deserialization capabilities
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Utf8JsonAsyncStreamReader:

Package Downloads
LionWeb-CSharp

This package contains the C# reference implementation of the LionWeb core functionality

Blazing.Json.Queryable

High-performance LINQ provider for JSON data that processes JSON directly without full deserialization. Supports standard string, UTF-8, streaming, and RFC 9535 compliant JSONPath operations. Dramatically improves performance and memory efficiency for medium to large JSON files through early termination and constant memory usage. Includes native IAsyncEnumerable support and .NET 10 async LINQ integration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 1,368 11/19/2025
2.0.0 328 11/17/2025
1.3.1 540 10/9/2025
1.3.0 205 10/8/2025
1.2.0 234 10/8/2025
1.1.0 50,769 11/9/2024
1.0.0 1,525 5/11/2023

v1.2.0 - .Net 9.0 update; symbols support to nuget; updated readme