Skip to content

Repository files navigation

Irihi.Text.Toon

NuGet License

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

Features

  • Reader/Writer API — Forward-only, zero-allocation Utf8ToonReader / Utf8ToonWriter
  • DOM ParserToonDocument / ToonElement with LINQ-like EnumerateObject / EnumerateArray
  • SerializerToonSerializer with drop-in System.Text.Json API compatibility
  • Source Generator — AOT-compatible fast-path serialization, zero reflection
  • ASP.NET Core — Input/output formatters for Web APIs (Accept: text/toon)
  • HttpClientGetFromToonAsync / PostAsToonAsync / PutAsToonAsync
  • Configuration.toon files as IConfiguration sources 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.

Quick Start

dotnet add package Irihi.Text.Toon
using 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);

Packages

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")

ASP.NET Core Integration

dotnet add package Irihi.AspNetCore.Mvc.Toon
builder.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.com

Configuration Provider

dotnet add package Irihi.Extensions.Configuration.Toon
builder.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.

Example

// 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());

Documentation

License

MIT © Irihi Tech

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages