TeaLeaf 2.0.0-beta.14

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

TeaLeaf

Schema-aware data format with human-readable text and compact binary representation.

Optimized for LLM context engineering -- schemas eliminate repeated field names, reducing data tokens by ~36% compared to JSON with no accuracy loss. Savings increase with larger, more structured datasets.

Features

  • Dual formats: Human-readable text (.tl) and compact binary (.tlbx)
  • Schema-aware: Automatic struct inference for uniform object arrays
  • Type-preserving: Full JSON type fidelity including number types
  • High-performance: Native Rust core with zero-copy parsing
  • Cross-platform: Windows, Linux, macOS (x64 and ARM64)

Installation

dotnet add package TeaLeaf

Quick Start

using TeaLeaf;

// Convert JSON to TeaLeaf document
string json = """{"name": "Alice", "age": 30}""";
using var doc = TLDocument.FromJson(json);

// Get the TeaLeaf text format (with schema definitions)
string tlText = doc.ToText();

// Convert back to JSON
string roundTrip = doc.ToJson();

// Compile to binary format for compact storage
doc.Compile("data.tlbx", compress: true);

// Read binary file
using var reader = TLReader.Open("data.tlbx");
string fromBinary = reader.ToJson();

// Access values by key
var name = reader.Get("name")?.AsString();

Working with Text Format (.tl)

using TeaLeaf;

// Parse TeaLeaf text
string tlText = """
    @struct Person (name: string, age: int)
    person: @Person ("Alice", 30)
    """;
using var doc = TLDocument.Parse(tlText);

// Access values
var person = doc.Get("person");
Console.WriteLine(person?.GetField("name")?.AsString()); // "Alice"

// Convert to JSON
Console.WriteLine(doc.ToJson());

Working with Binary Format (.tlbx)

using TeaLeaf;

// Create binary from JSON (one step)
TLReader.CreateFromJson(jsonString, "output.tlbx", compress: true);

// Or from a document
using var doc = TLDocument.FromJson(jsonString);
doc.Compile("output.tlbx", compress: true);

// Read binary file
using var reader = TLReader.Open("data.tlbx");

// Access data
foreach (var key in reader.Keys)
{
    Console.WriteLine($"{key}: {reader.GetAsJson(key)}");
}

// Memory-mapped reading for large files
using var mmapReader = TLReader.OpenMmap("large.tlbx");

DTO Serialization

Annotate your classes with [TeaLeaf] for reflection-based serialization:

using TeaLeaf;
using TeaLeaf.Annotations;

[TeaLeaf]
public class Employee
{
    public string Name { get; set; } = "";
    public int Age { get; set; }

    [TLRename("dept")]
    public string Department { get; set; } = "";

    [TLOptional]
    public string? Email { get; set; }
}

// Serialize to TeaLeaf text (with @struct schema)
var emp = new Employee { Name = "Alice", Age = 30, Department = "Engineering" };
string tlText = TeaLeafSerializer.ToDocument(emp);

// Serialize collection to TeaLeaf
var employees = new List<Employee> { emp };
string tableText = TeaLeafSerializer.ToText(employees, "employees");

// Compile directly to binary
TeaLeafSerializer.Compile(emp, "employee.tlbx", compress: true);

// Deserialize from TeaLeaf text
var restored = TeaLeafSerializer.FromText<Employee>(tlText);

// Deserialize from TLDocument
using var doc = TLDocument.Parse(tlText);
var fromDoc = TeaLeafSerializer.FromDocument<Employee>(doc);

Attributes

Attribute Description
[TeaLeaf] Marks a class for TeaLeaf serialization
[TeaLeaf(Generate = true)] Enables compile-time source generation (requires partial)
[TLKey("name")] Sets the top-level document key
[TLRename("name")] Overrides the field name in output
[TLType("float64")] Overrides the TeaLeaf type in schema
[TLOptional] Marks field as nullable in schema
[TLSkip] Excludes property from serialization

Source Generator

For compile-time code generation (better performance than reflection), add Generate = true and mark the class as partial:

[TeaLeaf(Generate = true)]
public partial class Employee
{
    public string Name { get; set; } = "";
    public int Age { get; set; }
}

This generates ToTeaLeafText(), FromTeaLeaf(), and other methods at compile time.

Supported Platforms

Platform Architecture
Windows x64, ARM64
Linux x64, ARM64
macOS x64 (Intel), ARM64 (Apple Silicon)

API Reference

TLDocument

For working with TeaLeaf text format (.tl):

Method Description
TLDocument.Parse(string text) Parse TeaLeaf text
TLDocument.ParseFile(string path) Parse from .tl file
TLDocument.FromJson(string json) Create from JSON with schema inference
doc.ToText() Convert to TeaLeaf text (with schemas, pretty-printed)
doc.ToText(compact, compactFloats, ignoreSchemas) Text with formatting and schema options
doc.ToJson() Convert to pretty JSON
doc.ToJsonCompact() Convert to compact JSON
doc.Compile(path, compress) Write to binary .tlbx file
doc.Get(key) Get value by key
doc.Keys Get all keys

TLReader

For reading binary TeaLeaf files (.tlbx):

Method Description
TLReader.Open(string path) Open binary file
TLReader.OpenMmap(string path) Open with memory mapping
TLReader.CreateFromJson(json, path, compress) Create binary from JSON
reader.ToJson() Convert to pretty JSON
reader.ToJsonCompact() Convert to compact JSON
reader.Get(key) Get value by key
reader.GetAsJson(key) Get value as JSON string
reader.Keys Get all keys
reader.Schemas Get schema definitions

TeaLeaf Format Example

JSON input:

{
  "users": [
    {"name": "Alice", "age": 30},
    {"name": "Bob", "age": 25}
  ]
}

TeaLeaf text output (with auto-inferred schema):

@struct User (name: string, age: int)

users: @table User [
  ("Alice", 30)
  ("Bob", 25)
]

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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. 
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
2.0.0-beta.14 50 2/17/2026
2.0.0-beta.13 49 2/13/2026
2.0.0-beta.12 56 2/13/2026
2.0.0-beta.11 53 2/12/2026
2.0.0-beta.10 50 2/12/2026
2.0.0-beta.9 51 2/12/2026
2.0.0-beta.8 58 2/10/2026
2.0.0-beta.7 48 2/10/2026
2.0.0-beta.6 52 2/10/2026
2.0.0-beta.5 47 2/10/2026
2.0.0-beta.4 50 2/9/2026
2.0.0-beta.3 52 2/9/2026
2.0.0-beta.2 51 2/4/2026
2.0.0-beta.1 46 2/4/2026