Juner.AspNetCore.Sequence 1.0.0-preview-2

This is a prerelease version of Juner.AspNetCore.Sequence.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Juner.AspNetCore.Sequence --version 1.0.0-preview-2
                    
NuGet\Install-Package Juner.AspNetCore.Sequence -Version 1.0.0-preview-2
                    
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="Juner.AspNetCore.Sequence" Version="1.0.0-preview-2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Juner.AspNetCore.Sequence" Version="1.0.0-preview-2" />
                    
Directory.Packages.props
<PackageReference Include="Juner.AspNetCore.Sequence" />
                    
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 Juner.AspNetCore.Sequence --version 1.0.0-preview-2
                    
#r "nuget: Juner.AspNetCore.Sequence, 1.0.0-preview-2"
                    
#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 Juner.AspNetCore.Sequence@1.0.0-preview-2
                    
#: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=Juner.AspNetCore.Sequence&version=1.0.0-preview-2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Juner.AspNetCore.Sequence&version=1.0.0-preview-2&prerelease
                    
Install as a Cake Tool

Juner.AspNetCore.Sequence

This package is currently in preview. APIs may change in future releases.

Streaming JSON formats (NDJSON, JSON Lines, JSON Sequence) for ASP.NET Core.

Juner.AspNetCore.Sequence is an ASP.NET Core formatter that provides streaming JSON support for:

  • NDJSON (application/x-ndjson)
  • JSON Lines (application/jsonl)
  • JSON Sequence (application/json-seq)
  • JSON Array (application/json)

It enables incremental serialization and deserialization using IAsyncEnumerable<T>, IEnumerable<T>, ChannelReader<T>, arrays, or lists.


Why this library? (The Gap in ASP.NET Core)

While ASP.NET Core natively supports IAsyncEnumerable<T> for application/json, it is limited to JSON arrays ([...]).

For streaming-friendly formats like:

  • NDJSON
  • JSON Lines
  • JSON Sequence

you typically need to:

  • implement custom InputFormatter / OutputFormatter
  • manually parse request bodies
  • handle Minimal API binding yourself

This library fills that gap by enabling consistent streaming handling across formats.


Quick Example (Minimal API)

app.MapPost("/process", async (Sequence<Person> sequence) =>
{
    await foreach (var person in sequence)
    {
        Console.WriteLine($"Received: {person.Name}");
    }

    return Results.Ok();
});

Request (NDJSON):

{"name":"alice"}
{"name":"bob"}

Installation

dotnet add package Juner.AspNetCore.Sequence

Setup

Minimal API

builder.Services.AddSequenceOpenApi();

ASP.NET Core (MVC)

builder.Services.AddSequenceOpenApi();
builder.Services.AddControllers()
    .AddSequenceFormatter();
``

---

## Features

* Supports multiple streaming formats

  * NDJSON
  * JSON Lines
  * JSON Sequence
  * JSON Array
* Supports multiple sequence sources

  * `IAsyncEnumerable<T>`
  * `IEnumerable<T>`
  * `T[]`
  * `List<T>`
  * `ChannelReader<T>`
* Minimal API ready (`Sequence<T>` binding)
* Results extensions (`Results.*`, `TypedResults.*`)
* Incremental JSON parsing
* Built on `System.Text.Json` and `PipeReader`
* Low memory usage (streaming, non-buffered)

---

## Usage

### Minimal API

```csharp
app.MapPost("/ndjson",
    async (Sequence<Person> sequence) =>
    {
        await foreach (var item in sequence)
        {
            Console.WriteLine(item.Name);
        }

        return Results.Ok();
    });

MVC Controller

[HttpPost]
[Consumes("application/x-ndjson")]
public async Task<IActionResult> Post([FromBody] IAsyncEnumerable<Person> data)
{
    await foreach (var item in data)
    {
        Console.WriteLine(item.Name);
    }

    return Ok();
}

Results APIs

This library provides multiple ways to return streaming responses.

SequenceResults (baseline API)

SequenceResults.NdJson(sequence)

Works in all environments without relying on extension methods.


Results / TypedResults extensions

Results.NdJson(sequence)
TypedResults.NdJson(sequence)

Provides a more natural Minimal API experience.


Which should I use?

  • Use SequenceResults if:

    • you need maximum compatibility
    • you prefer explicit usage
  • Use Results / TypedResults if:

    • you are using modern ASP.NET Core
    • you prefer idiomatic Minimal API style

All APIs produce the same streaming behavior.


Supported Formats

Format RFC Content-Type Notes
JSON Sequence RFC 7464 application/json-seq record separator based
NDJSON informal application/x-ndjson newline delimited
JSON Lines informal application/jsonl similar to NDJSON
JSON Array RFC 8259 application/json buffered or streaming-compatible

Supported Input Types

  • IAsyncEnumerable<T>
  • IEnumerable<T>
  • T[]
  • List<T>
  • ChannelReader<T>
  • Sequence<T>

Supported Output Types

  • IAsyncEnumerable<T>
  • IEnumerable<T>
  • T[]
  • List<T>
  • ChannelReader<T>

Why not just use [FromBody]?

app.MapPost("/json",
    async ([FromBody] IAsyncEnumerable<MyObject> items) =>
    {
        await foreach (var item in items)
        {
            Console.WriteLine(item.Id);
        }
    });

This expects a JSON array:

[
 { "id": 1 },
 { "id": 2 }
]

It does not support streaming formats like NDJSON.


With Sequence<T>

app.MapPost("/ndjson",
    async (Sequence<MyObject> sequence) =>
    {
        await foreach (var item in sequence)
        {
            Console.WriteLine(item.Id);
        }
    });

Request:

{"id":1}
{"id":2}
{"id":3}

Comparison

Feature Standard ASP.NET Core With This Library
JSON Array
NDJSON / JSONL
JSON Sequence
Minimal API binding ⚠️ JSON only
Request streaming (NDJSON etc.)
Streaming output ⚠️ limited

OpenAPI support

AddSequenceOpenApi() is currently available only for .NET 10

OpenAPI (Swagger) does not fully support streaming formats such as:

  • NDJSON
  • JSON Lines
  • JSON Sequence

To avoid misleading schemas, response type information may be omitted.

Please refer to the examples for actual usage.

Support may improve with future OpenAPI versions (e.g. 3.2).


Internals

The formatter integrates with ASP.NET Core's formatter pipeline.

Supported formats can be bound to multiple types, including:

  • IAsyncEnumerable<T>
  • ChannelReader<T>
  • Sequence<T>

Sequence<T> is a wrapper that enables unified streaming input handling across formats.

The implementation is based on:

  • System.Text.Json
  • PipeReader

Serialization and deserialization are performed incrementally.


Target Framework

  • .NET 7
  • .NET 8
  • .NET 9
  • .NET 10
  • ASP.NET Core

License

MIT

See also

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 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 106 3/30/2026
1.0.0-preview-2 104 3/26/2026
1.0.0-preview-1 112 3/21/2026 1.0.0-preview-1 is deprecated because it has critical bugs.