ToonFormat 0.1.1

dotnet add package ToonFormat --version 0.1.1
                    
NuGet\Install-Package ToonFormat -Version 0.1.1
                    
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="ToonFormat" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ToonFormat" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="ToonFormat" />
                    
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 ToonFormat --version 0.1.1
                    
#r "nuget: ToonFormat, 0.1.1"
                    
#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 ToonFormat@0.1.1
                    
#: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=ToonFormat&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=ToonFormat&version=0.1.1
                    
Install as a Cake Tool

ToonFormat

C# implementation of Token-Oriented Object Notation (TOON) – A compact, human-readable, schema-aware JSON format designed for LLM prompts.

TOON reduces token usage by 30-60% compared to JSON by eliminating redundant punctuation and using a tabular format for uniform data structures.

Features

  • Token Efficient: 30-60% fewer tokens than JSON
  • Tabular Format: Optimized for arrays of uniform objects
  • Round-trip Safe: Lossless encoding/decoding
  • .NET Native: Simple API similar to JSON serialization
  • Human Readable: Easy to read and debug
  • Cross-platform: Supports .NET Standard 2.0+

Installation

Install from NuGet Package Manager:

Install-Package ToonFormat

Or using .NET CLI:

dotnet add package ToonFormat

Global Tool (CLI)

Install the global tool for command-line usage:

dotnet tool install -g ToonFormat.Tool

After installation, use the toon command:

# Convert JSON to TOON
toon encode input.json
toon encode input.json -o output.toon

# Convert TOON to JSON
toon decode input.toon
toon decode input.toon -o output.json

# Read from stdin
echo '{"key": "value"}' | toon encode
cat data.toon | toon decode

Quick Start

using ToonFormat;

// Encode C# objects to TOON
var data = new Dictionary<string, object>
{
    ["products"] = new List<Dictionary<string, object>>
    {
        new Dictionary<string, object> { ["sku"] = "A123", ["name"] = "Widget", ["price"] = 9.99 },
        new Dictionary<string, object> { ["sku"] = "B456", ["name"] = "Gadget", ["price"] = 19.99 }
    }
};

var toon = ToonFormat.Encode(data);
Console.WriteLine(toon);
// products[2]{sku,name,price}:
//   A123,Widget,9.99
//   B456,Gadget,19.99

// Decode TOON back to C# objects
var decoded = ToonFormat.Decode(toon);

Usage

Encoding

using ToonFormat;

// Simple object
var simple = new Dictionary<string, object>
{
    ["id"] = 1,
    ["name"] = "Alice"
};
var toon = ToonFormat.Encode(simple);
// id: 1
// name: Alice

// Nested object
var nested = new Dictionary<string, object>
{
    ["user"] = new Dictionary<string, object>
    {
        ["id"] = 1,
        ["name"] = "Alice"
    }
};
var toonNested = ToonFormat.Encode(nested);
// user:
//   id: 1
//   name: Alice

// Tabular array (uniform objects)
var items = new Dictionary<string, object>
{
    ["items"] = new List<Dictionary<string, object>>
    {
        new Dictionary<string, object> { ["sku"] = "A1", ["qty"] = 2 },
        new Dictionary<string, object> { ["sku"] = "B2", ["qty"] = 1 }
    }
};
var toonItems = ToonFormat.Encode(items);
// items[2]{sku,qty}:
//   A1,2
//   B2,1

// Custom delimiter
var toonTab = ToonFormat.Encode(items, delimiter: "\t");

Decoding

using ToonFormat;

var toon = @"
products[2]{sku,name,price}:
  A123,Widget,9.99
  B456,Gadget,19.99
";

var data = ToonFormat.Decode(toon);
// Returns Dictionary<string, object> with products array

File I/O

using ToonFormat;

// Load from file
var data = ToonFormat.Load("data.toon");

// Save to file
ToonFormat.Save(data, "output.toon");

Token Comparison

using ToonFormat;

var data = new Dictionary<string, object>
{
    ["products"] = new List<Dictionary<string, object>>
    {
        new Dictionary<string, object> { ["id"] = 1, ["name"] = "Product 1" },
        new Dictionary<string, object> { ["id"] = 2, ["name"] = "Product 2" }
    }
};

var metrics = ToonFormat.CompareSizes(data);
Console.WriteLine($"Token reduction: {metrics.TokenReduction:F1}%");
Console.WriteLine($"Size reduction: {metrics.SizeReduction:F1}%");

API Reference

ToonFormat.Encode(object? obj, int indent = 2, string delimiter = ",")

Converts C# objects to TOON format.

Parameters:

  • obj: C# object (Dictionary, List, or primitive)
  • indent: Number of spaces per indentation level (default: 2)
  • delimiter: Field delimiter for tabular arrays (default: ",")

Returns: TOON-formatted string

ToonFormat.Decode(string toonString, int indent = 2, bool strict = true)

Converts TOON-formatted string to C# objects.

Parameters:

  • toonString: TOON-formatted string
  • indent: Expected indentation level (default: 2)
  • strict: Enable strict validation (default: true)

Returns: C# object (Dictionary, List, or primitive)

ToonFormat.Load(string filePath, int indent = 2, bool strict = true)

Loads TOON data from a file.

ToonFormat.Save(object? obj, string filePath, int indent = 2, string delimiter = ",")

Saves an object to a TOON file.

ToonFormat.CompareSizes(object? obj, int jsonIndent = 2)

Compares JSON and TOON representations.

Returns: ComparisonMetrics object with:

  • JsonSize: JSON string length
  • ToonSize: TOON string length
  • JsonTokens: Approximate JSON token count
  • ToonTokens: Approximate TOON token count
  • SizeReduction: Percentage reduction in size
  • TokenReduction: Percentage reduction in tokens

Format Examples

Object

new Dictionary<string, object> { ["id"] = 1, ["name"] = "Ada" }
// →
// id: 1
// name: Ada

Nested Object

new Dictionary<string, object>
{
    ["user"] = new Dictionary<string, object> { ["id"] = 1 }
}
// →
// user:
//   id: 1

Tabular Array (Uniform Objects)

new Dictionary<string, object>
{
    ["items"] = new List<Dictionary<string, object>>
    {
        new Dictionary<string, object> { ["id"] = 1, ["qty"] = 5 },
        new Dictionary<string, object> { ["id"] = 2, ["qty"] = 3 }
    }
}
// →
// items[2]{id,qty}:
//   1,5
//   2,3

When to Use TOON

TOON excels at:

  • Uniform arrays of objects (same fields, primitive values)
  • Large datasets with consistent structure
  • LLM prompts where token efficiency matters

JSON is better for:

  • Non-uniform data
  • Deeply nested structures
  • Objects with varying field sets
  • API responses and storage

Token Savings

TOON achieves significant token savings, especially for tabular data:

JSON: ~45 tokens

{
  "products": [
    {"sku": "A123", "name": "Widget", "price": 9.99},
    {"sku": "B456", "name": "Gadget", "price": 19.99}
  ]
}

TOON: ~19 tokens (58% reduction)

products[2]{sku,name,price}:
  A123,Widget,9.99
  B456,Gadget,19.99

Requirements

  • .NET Standard 2.0 or higher
  • .NET Core 2.0+ or .NET Framework 4.6.1+

License

MIT License

Credits

  • Based on TOON format by Johann Schopplich
  • C# implementation by Ertugrul Kara
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.1.1 1,753 11/14/2025
0.1.0 264 11/14/2025

Initial release of ToonFormat for .NET