Catalog · How the catalog works
delphi-toon
TOON Format for Delphi
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
TOON Format for Delphi
⚠️ Beta Status (v0.9.x): This library is in active development and working towards spec compliance.
Compact, human-readable serialization format for LLM contexts with 30-60% token reduction vs JSON. Combines YAML-like indentation with CSV-like tabular arrays. Working towards full compatibility with the official TOON specification.
Key Features: Minimal syntax • Tabular arrays for uniform data • Array length validation • Delphi 11+ compatible • Comprehensive test coverage.
Installation
- Clone or download this repository
- Add the
srcfolder to your Delphi search path - Add
Toon.Formatto your uses clause
Quick Start
uses
Toon.Format;
var
Encoder: TToonEncoder;
Decoder: TToonDecoder;
JsonValue: TJSONValue;
ToonStr: string;
begin
// Create encoder
Encoder := TToonEncoder.Create;
try
// Simple object
JsonValue := TJSONObject.ParseJSONValue('{"name": "Alice", "age": 30}');
try
ToonStr := Encoder.Encode(JsonValue);
// name: Alice
// age: 30
finally
JsonValue.Free;
end;
finally
Encoder.Free;
end;
// Create decoder
Decoder := TToonDecoder.Create;
try
// Decode back to JSON
JsonValue := Decoder.Decode('name: Alice' + sLineBreak + 'age: 30');
try
// Use JsonValue...
finally
JsonValue.Free;
end;
finally
Decoder.Free;
end;
end;Format Specification
| Type | Example Input | TOON Output |
|---|---|---|
| Object | {"name": "Alice", "age": 30} |
name: Alice |
age: 30 |
||
| Primitive Array | [1, 2, 3] |
[3]: 1,2,3 |
| Tabular Array | [{"id": 1, "name": "A"}, {"id": 2, "name": "B"}] |
[2,]{id,name}: |
1,A |
||
2,B |
||
| Mixed Array | [{"x": 1}, 42, "hi"] |
[3]: |
- x: 1 |
||
- 42 |
||
- hi |
API Reference
TToonEncoder
TToonEncoder = class
public
constructor Create(AOptions: TToonEncodeOptions = nil);
destructor Destroy; override;
function Encode(Value: TJSONValue): string;
property Options: TToonEncodeOptions read FOptions write FOptions;
end;TToonDecoder
TToonDecoder = class
public
constructor Create(AOptions: TToonDecodeOptions = nil);
destructor Destroy; override;
function Decode(const Input: string): TJSONValue;
property Options: TToonDecodeOptions read FOptions write FOptions;
end;Options
// Encoding options
TToonEncodeOptions = class
property Indent: Integer; // Spaces per level (default: 2)
property Delimiter: TDelimiter; // comma, tab, or pipe (default: comma)
property LengthMarker: Boolean; // Prefix array lengths with # (default: False)
end;
// Decoding options
TToonDecodeOptions = class
property Indent: Integer; // Expected indent size (default: 2)
property Strict: Boolean; // Validate syntax (default: True)
end;Format Examples
Objects
name: Alice
age: 30
email: alice@example.comPrimitive Arrays
[3]: 1,2,3Tabular Arrays (Uniform Objects)
[2,]{id,name,active}:
1,Alice,true
2,Bob,falseMixed/Non-uniform Arrays
[3]:
- type: user
id: 1
- 42
- hello worldProject Status & Roadmap
Following semantic versioning towards 1.0.0:
- v0.8.x - Initial code set, tests, documentation ✅
- v0.9.x - Encoder/decoder implementation, spec compliance testing (current)
- v1.0.0-rc.x - Release candidates for production readiness
- v1.0.0 - First stable release with full spec compliance
Documentation
- 📘 Full Documentation - Complete guides and references
- 📋 Format Specification - Official TOON specification
- 🐍 Python Implementation - Reference implementation
Contributors
This Delphi implementation is a community-driven port based on the Python reference implementation.
License
MIT License – see LICENSE for details.

