High-performance TOON format serialization library for .NET.
TOON is a human-readable, indentation-based data format — simpler than YAML, more expressive than JSON.
TOON Format: Official Website · Specification · Repository
- Reader/Writer API — Forward-only, zero-allocation
Utf8ToonReader/Utf8ToonWriter - DOM Parser —
ToonDocument/ToonElementwith LINQ-likeEnumerateObject/EnumerateArray - Serializer —
ToonSerializerwith drop-inSystem.Text.JsonAPI compatibility - Source Generator — AOT-compatible fast-path serialization, zero reflection
- ASP.NET Core — Input/output formatters for Web APIs (
Accept: text/toon) - HttpClient —
GetFromToonAsync/PostAsToonAsync/PutAsToonAsync - Configuration —
.toonfiles asIConfigurationsources with reload-on-change - SIMD Accelerated — Vectorized indent counting, escape detection
- Key Folding — Dotted keys expand to nested objects (
server.host: localhost→{server: {host: localhost}}) - List Arrays — Mixed-array format (scalar, inline object, nested). Deserialization of heterogeneous list items not yet supported.
dotnet add package Irihi.Text.Toonusing Irihi.Text.Toon;
var person = new Person { Name = "Alice", Age = 30 };
// Serialize
string toon = ToonSerializer.Serialize(person);
// Name: Alice
// Age: 30
// Deserialize
Person? restored = ToonSerializer.Deserialize<Person>(toon);| Package | Description |
|---|---|
Irihi.Text.Toon |
Core library: Reader, Writer, DOM, Serializer, Source Generator, HttpClient |
Irihi.AspNetCore.Mvc.Toon |
ASP.NET Core input/output formatters |
Irihi.Extensions.Configuration.Toon |
.NET config source for .toon files — AddToonFile("appsettings.toon") |
dotnet add package Irihi.AspNetCore.Mvc.Toonbuilder.Services.AddControllers().AddToonFormatters();Clients sending Accept: text/toon receive TOON responses.
Clients sending Content-Type: text/toon can POST/PUT TOON request bodies.
curl -H "Accept: text/toon" http://localhost:5000/users
# Id: 1
# Name: Alice
# Email: alice@example.comdotnet add package Irihi.Extensions.Configuration.Toonbuilder.Configuration.AddToonFile("appsettings.toon", optional: true, reloadOnChange: true);
builder.Services.Configure<AppOptions>(builder.Configuration.GetSection("App"));# appsettings.toon
App:
Name: ToonDemo
Version: "1.0"
Servers[3]: server1.local,server2.local,server3.local
Then use IOptions<AppOptions> via dependency injection as usual.
// Tabular arrays
var users = new List<User> { new("Alice", 30), new("Bob", 25) };
var opts = new ToonSerializerOptions { TabularArrayMode = ToonTabularArrayMode.Auto };
Console.WriteLine(ToonSerializer.Serialize(users, opts));
// [2]{Name,Age}:
// Alice,30
// Bob,25
// Source generator (AOT-compatible)
[ToonSerializable(typeof(User))]
public partial class AppContext : ToonSerializerContext { }
var fastToon = ToonSerializer.Serialize(user, new AppContext());MIT © Irihi Tech