Skip to main content

Welcome to ToonNet

ToonNet is a .NET library for serializing and deserializing data in TOON (Token-Oriented Object Notation) format. It implements TOON spec v4.4, passes all 564 official conformance fixtures and writes the same text as the official .NET library.

What is TOON?​

TOON is a human-readable data format designed for:

  • AI/LLM prompts - Fewer tokens than JSON, especially for arrays of uniform objects
  • Configuration files - Clean, readable syntax
  • Data exchange - Human and machine friendly

Quick Example​

using ToonNet.Core.Serialization;

// Serialize
var person = new Person { Name = "Alice", Age = 30 };
string toon = ToonSerializer.Serialize(person); // Name: Alice\nAge: 30

// Deserialize
var restored = ToonSerializer.Deserialize<Person>(toon);

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

Key Features​

  • πŸš€ Performance - Compiled accessors, cached type metadata, span-based parsing and pooled buffers
  • πŸ’° Token Efficient - Tabular arrays and keyed tables declare field names once, nested field groups flatten uniform nested objects into the same rows (lower AI API costs)
  • πŸ“ Spec v4.4 - All 564 official conformance fixtures pass; output is identical to the official .NET library
  • 🎯 .NET 8, .NET 10 and .NET 11 - Builds for .NET 8 and .NET 10; tested on .NET 11 too
  • πŸ’» Developer Friendly - System.Text.Json-style API
  • πŸ”„ Streaming Support - Multi-document streaming from IAsyncEnumerable<T> without materializing the whole dataset
  • πŸ”§ ASP.NET Core - Input/output formatters, configuration provider
  • πŸ“¦ Format Extensions - JSON/YAML bidirectional conversion
  • 🎯 Source Generators - Optional generated Serialize/Deserialize methods with the same output as ToonSerializer

Beyond Serialization​

Other TOON libraries convert values to and from text. ToonNet also lets you work with TOON data where it is, without converting it first:

You want toWith ToonNetPage
Find values: the rows over a limit, the users of a domainJSONPath (RFC 9535, all 715 compliance cases) plus string, type and aggregate functions: $.orders[?sum(@.lines[*].price) > 1000]Querying
Read one part of a large documentDeserializeAt<T>(toon, "$.data.orders") skips the rest without building it (about 20x faster for a small part)Querying
Read only the rows that matchDeserializeAll<T>(toon, "$.orders[?@.total > 100]"), filtered on the text (2.3x faster, 13x less memory than LINQ after deserializing)Querying
Stream a large array inside a responseDeserializeAsyncEnumerableAt<T>(stream, "$.data.orders") with flat memoryStreaming
Check business rulesToonRuleSet: Schematron-style rules ("@.total >= 0", Unique, Forbidden("$..password")) with the path of every violationRules and Validation
Change a documentIndexers, SetValue/RemoveAll by path, DeepClone, DeepEquals, JSON Merge PatchEditing Trees
Talk to a language modelShortened data for prompts, answer templates, lenient and validated reading of answersLanguage Models
Accept queries from clientsLimits on length, nesting, work and time (ToonPathOptions), linear-time regular expressionsQuerying

Documentation Guide​

πŸš€ Getting Started​

Start here if you're new to ToonNet:

🎯 Core Features​

Deep dive into ToonNet's core functionality:

πŸ”Œ Format Extensions​

Convert between different data formats:

🌐 ASP.NET Core​

Integrate ToonNet with ASP.NET Core:

⚑ Advanced Topics​

Optimization and customization:

πŸ“š Reference​

Additional resources:

  • API Guide - The API at a glance, in the style of System.Text.Json
  • TOON Spec - TOON spec v4.4 conformance and implementation notes
  • ToonNet vs Toon.Format - Features and measurements next to the official library
TopicLink
InstallationGetting Started
First ExampleQuick Start
API OverviewAPI Guide
Large FilesStreaming
Compared With Toon.FormatToonNet vs Toon.Format
GitHub RepositoryToonNet on GitHub

Community & Support​

License​

ToonNet is open-source software licensed under the MIT License.

Thread-Safety​

ToonSerializer and a shared ToonEncoder are safe to use from several threads; see Configuration for the caches and options.