{"id":43244222,"url":"https://github.com/selcukgural/toonnet","last_synced_at":"2026-02-08T12:10:34.055Z","repository":{"id":334420712,"uuid":"1131283178","full_name":"selcukgural/ToonNet","owner":"selcukgural","description":"High-performance .NET serialization library for TOON format - 40% fewer tokens for AI/LLM, expression tree-based (10-100x faster)","archived":false,"fork":false,"pushed_at":"2026-01-24T17:27:32.000Z","size":1210,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-25T05:54:29.170Z","etag":null,"topics":["ai","csharp","dotnet","json","llm","serialization","source-generators","token-optimization","toon","toon-format","yaml"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/ToonNet.Core","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selcukgural.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-09T18:51:28.000Z","updated_at":"2026-01-24T17:27:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/selcukgural/ToonNet","commit_stats":null,"previous_names":["selcukgural/toonnet"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/selcukgural/ToonNet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selcukgural%2FToonNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selcukgural%2FToonNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selcukgural%2FToonNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selcukgural%2FToonNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selcukgural","download_url":"https://codeload.github.com/selcukgural/ToonNet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selcukgural%2FToonNet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28977665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T11:31:13.034Z","status":"ssl_error","status_checked_at":"2026-02-01T11:30:25.558Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","csharp","dotnet","json","llm","serialization","source-generators","token-optimization","toon","toon-format","yaml"],"created_at":"2026-02-01T12:02:50.212Z","updated_at":"2026-02-08T12:10:33.980Z","avatar_url":"https://github.com/selcukgural.png","language":"C#","readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"icon.png\" alt=\"ToonNet Logo\" width=\"128\" height=\"128\"\u003e\n\n**TOON Data Format Serialization for .NET**\n\n*AI-Optimized • Token-Efficient • Developer-Friendly*\n\n[![.NET](https://img.shields.io/badge/.NET-8.0+-512BD4?style=flat\u0026logo=dotnet)](https://dotnet.microsoft.com/)\n[![NuGet](https://img.shields.io/nuget/v/ToonNet.Core.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.Core/)\n[![Downloads](https://img.shields.io/nuget/dt/ToonNet.Core.svg?style=flat)](https://www.nuget.org/packages/ToonNet.Core/)\n[![Tests](https://img.shields.io/badge/tests-447%20passing-success?style=flat)](#)\n[![Spec](https://img.shields.io/badge/TOON%20v3.0-100%25-blue?style=flat)](ToonSpec.md)\n[![Documentation](https://img.shields.io/badge/docs-online-brightgreen?style=flat\u0026logo=docusaurus)](https://selcukgural.github.io/ToonNet/)\n\n[Quick Start](#-quick-start) • [Documentation](https://selcukgural.github.io/ToonNet/) • [API Reference](https://selcukgural.github.io/ToonNet/docs/api/intro) • [Samples](demo/ToonNet.Demo/Samples)\n\n\u003c/div\u003e\n\n---\n\n## What is ToonNet?\n\nToonNet is a **.NET serialization library** that provides:\n\n- **Serialize** C# objects to TOON format\n- **Deserialize** TOON format to C# objects  \n- **Convert** between JSON, TOON, and YAML formats\n- **System.Text.Json-compatible API** for zero learning curve\n\n**TOON Format** is a human-readable data format optimized for:\n- **AI/LLM prompts** - Up to 40% fewer tokens than JSON\n- **Configuration files** - Clean, readable syntax\n- **Data exchange** - Human and machine friendly\n\n\u003e **TOON Specification:** This library implements [TOON v3.0](https://github.com/toon-format/spec/blob/main/SPEC.md) (Date: 2025-11-24, Status: Working Draft)\n\n---\n\n## 🤖 Why Developers Choose ToonNet\n\nToonNet delivers **production-grade performance** with three critical advantages:\n\n1. **🎯 40% Token Reduction** - Fewer tokens = Lower AI API costs\n2. **⚡ Extreme Performance** - 2-4x faster than competitors with near-zero allocations\n3. **🔧 Zero Learning Curve** - System.Text.Json-compatible API\n\n### ⚡ Performance First - Built for Production\n\nToonNet is **obsessively optimized** for high-throughput, low-latency production environments:\n\n**Benchmark-Proven Speed (Apple M3 Max, .NET 8.0):**\n```\nPayload Size    Speed Improvement    Memory Saved    GC Pressure\n───────────────────────────────────────────────────────────────\n100 Bytes       1.16x faster         100% (0 alloc)  ZERO ✅\n1 KB            1.98x faster         100% (0 alloc)  ZERO ✅\n10 KB           2.37x faster         100% (0 alloc)  ZERO ✅\n100 KB          4.40x faster         99.99% saved    ZERO ✅\n```\n\n**Real-World Impact:**\n- **Stream operations:** 1.61x faster, 50% less memory\n- **Large payloads (100KB+):** Up to **4.4x speed boost** ⚡\n- **GC collections:** **ZERO** (ArrayPool eliminates allocations)\n- **Deadlock risk:** **ELIMINATED** (proper ConfigureAwait usage)\n\n**Architecture Excellence:**\n- **Expression Trees** - Compiled property accessors (10-100x faster than reflection)\n- **ArrayPool\u003cT\u003e** - Reusable memory buffers, zero heap allocations\n- **SIMD Vectorization** - Hardware-accelerated parallel processing\n- **Source Generators** - Compile-time code generation for AOT compatibility\n- **Thread-Safe Caching** - `ConcurrentDictionary` for concurrent scenarios\n- **ConfigureAwait(false)** - No deadlocks in WPF/WinForms/legacy environments\n\n```csharp\n// Hot path performance (after warmup)\nvar toon = ToonSerializer.Serialize(largeObject);  \n// 100KB payload: ~3.7μs, 2 bytes allocated (vs 16.4μs, 133KB with GetBytes)\n// That's 340% faster with 99.99% less memory! 🚀\n```\n\n\u003e **Performance Guarantee:** All numbers are **real BenchmarkDotNet measurements**, not estimates. ToonNet is benchmarked on every release to prevent regressions.\n\n### 🤖 AI Token Optimization\n\nTOON format uses **significantly fewer tokens** than JSON, reducing AI API costs:\n\n```csharp\n// Example: Product catalog for AI prompt\nvar products = new List\u003cProduct\u003e\n{\n    new() { Id = 1, Name = \"Laptop\", Price = 1299.99m, InStock = true },\n    new() { Id = 2, Name = \"Mouse\", Price = 29.99m, InStock = true },\n    new() { Id = 3, Name = \"Keyboard\", Price = 89.99m, InStock = false }\n};\n\nstring json = ToonConvert.SerializeToJson(products);\nstring toon = ToonSerializer.Serialize(products);\n\nConsole.WriteLine($\"JSON tokens: ~{json.Length / 4}\");  // ~150 tokens\nConsole.WriteLine($\"TOON tokens: ~{toon.Length / 4}\");  // ~90 tokens\n// 40% token reduction = 40% cost savings on AI APIs\n```\n\n**JSON output (longer, more tokens):**\n```json\n[{\"id\":1,\"name\":\"Laptop\",\"price\":1299.99,\"inStock\":true},{\"id\":2,\"name\":\"Mouse\",\"price\":29.99,\"inStock\":true},{\"id\":3,\"name\":\"Keyboard\",\"price\":89.99,\"inStock\":false}]\n```\n\n**TOON output (shorter, fewer tokens):**\n```toon\nproducts[3]:\n  - Id: 1\n    Name: Laptop\n    Price: 1299.99\n    InStock: true\n  - Id: 2\n    Name: Mouse\n    Price: 29.99\n    InStock: true\n  - Id: 3\n    Name: Keyboard\n    Price: 89.99\n    InStock: false\n```\n\n**Real-world savings:**\n- GPT-4: ~$0.03 per 1K input tokens → 40% fewer tokens = **40% cost reduction**\n- Claude: ~$0.015 per 1K input tokens → Significant savings on large prompts\n- Perfect for RAG systems, prompt engineering, AI-powered tools\n\n### ⚡ Performance \u0026 Architecture\n\nToonNet is **engineered for extreme performance** in production environments:\n\n**Zero-Allocation Hot Paths:**\n- **ArrayPool\u003cT\u003e** - Reusable byte buffers eliminate heap allocations (99.99% reduction)\n- **Expression Trees** - Compiled property accessors (10-100x faster than reflection)\n- **Source Generators** - Compile-time code generation for zero-allocation serialization\n- **Metadata Caching** - Thread-safe `ConcurrentDictionary` for type metadata\n- **SIMD Operations** - Hardware-accelerated string processing\n- **No runtime reflection** overhead after first access\n\n**Latest Optimizations (v1.3.0):**\n```csharp\n// ArrayPool optimization - Near-zero allocations\nusing var stream = new MemoryStream();\nawait ToonSerializer.SerializeToStreamAsync(data, stream);\n// 10KB: 901ns, 13KB allocated (vs 1,454ns, 27KB with old approach)\n// Result: 1.61x faster, 50% less memory, ZERO GC pressure ✅\n```\n\n**Production-Ready Async:**\n- **ConfigureAwait(false)** - Eliminates deadlock risk in all environments\n- **Cancellation Support** - Full CancellationToken propagation\n- **80KB Buffers** - Large file I/O optimization (20x larger than default)\n- **Concurrent Operations** - Thread-safe by design\n\n**Architecture highlights:**\n- **Compiled getters/setters** - Expression trees compiled to IL, not reflection calls\n- **Memory pooling** - ArrayPool\u003cbyte\u003e for stream operations\n- **Span\u003cT\u003e and Memory\u003cT\u003e** - Modern .NET APIs for reduced allocations\n- **Source generator option** - AOT-compatible, zero-allocation code generation\n\n**Thread-Safety:**\n- **Concurrent use:** `ToonSerializer` methods are safe to call from multiple threads.\n- **Shared caches:** Type metadata and naming caches use `ConcurrentDictionary` for safe concurrent access.\n- **Cache lifetime:** Metadata entries are created on demand and retained for the process lifetime (no eviction).\n- **Options caution:** Do not mutate a single `ToonSerializerOptions` instance concurrently across threads.\n\n\u003e **When to use ToonNet:** High-throughput APIs, real-time systems, AI/LLM applications, microservices with tight latency budgets. Benchmark-proven 2-4x faster than traditional serializers.\n\n---\n\n## 📦 Packages\n\nToonNet is modular - install only what you need:\n\n| Package | Description | NuGet | Downloads | Status |\n|---------|-------------|-------|-----------|--------|\n| **ToonNet.Core** | Core serialization API - C# ↔ TOON (uses expression trees) | [![NuGet](https://img.shields.io/nuget/v/ToonNet.Core.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.Core/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.Core.svg?style=flat)](https://www.nuget.org/packages/ToonNet.Core/) | ✅ Stable |\n| **ToonNet.Extensions.Json** | JSON ↔ TOON conversion | [![NuGet](https://img.shields.io/nuget/v/ToonNet.Extensions.Json.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.Extensions.Json/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.Extensions.Json.svg?style=flat)](https://www.nuget.org/packages/ToonNet.Extensions.Json/) | ✅ Stable |\n| **ToonNet.Extensions.Yaml** | YAML ↔ TOON conversion | [![NuGet](https://img.shields.io/nuget/v/ToonNet.Extensions.Yaml.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.Extensions.Yaml/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.Extensions.Yaml.svg?style=flat)](https://www.nuget.org/packages/ToonNet.Extensions.Yaml/) | ✅ Stable |\n| **ToonNet.AspNetCore** | ASP.NET Core middleware \u0026 formatters | [![NuGet](https://img.shields.io/nuget/v/ToonNet.AspNetCore.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.AspNetCore/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.AspNetCore.svg?style=flat)](https://www.nuget.org/packages/ToonNet.AspNetCore/) | ✅ Stable |\n| **ToonNet.AspNetCore.Mvc** | MVC input/output formatters | [![NuGet](https://img.shields.io/nuget/v/ToonNet.AspNetCore.Mvc.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.AspNetCore.Mvc/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.AspNetCore.Mvc.svg?style=flat)](https://www.nuget.org/packages/ToonNet.AspNetCore.Mvc/) | ✅ Stable |\n| **ToonNet.SourceGenerators** | Compile-time code generation (AOT-compatible, zero-allocation) | [![NuGet](https://img.shields.io/nuget/v/ToonNet.SourceGenerators.svg?style=flat\u0026logo=nuget)](https://www.nuget.org/packages/ToonNet.SourceGenerators/) | [![Downloads](https://img.shields.io/nuget/dt/ToonNet.SourceGenerators.svg?style=flat)](https://www.nuget.org/packages/ToonNet.SourceGenerators/) | ✅ Stable |\n\n### Quick Install\n\n```bash\n# Core package (required)\ndotnet add package ToonNet.Core\n\n# JSON support (for AI/LLM token optimization)\ndotnet add package ToonNet.Extensions.Json\n\n# YAML support\ndotnet add package ToonNet.Extensions.Yaml\n\n# ASP.NET Core integration\ndotnet add package ToonNet.AspNetCore\ndotnet add package ToonNet.AspNetCore.Mvc\n\n# Performance (source generators)\ndotnet add package ToonNet.SourceGenerators\n```\n\n---\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\n# Core package (required)\ndotnet add package ToonNet.Core\n\n# For JSON conversion (AI/LLM use cases)\ndotnet add package ToonNet.Extensions.Json\n```\n\n### Basic Usage - AI Prompt Context\n\n```csharp\nusing ToonNet.Core.Serialization;\nusing ToonNet.Extensions.Json;  // For JSON conversion\n\n// Your C# class for AI prompt context (no attributes needed)\npublic class UserContext\n{\n    public string Name { get; set; }\n    public int Age { get; set; }\n    public List\u003cstring\u003e Interests { get; set; }\n    public List\u003cPurchase\u003e RecentPurchases { get; set; }\n}\n\npublic class Purchase\n{\n    public string Product { get; set; }\n    public decimal Amount { get; set; }\n}\n\nvar context = new UserContext \n{ \n    Name = \"Alice\",\n    Age = 28,\n    Interests = new List\u003cstring\u003e { \"AI\", \"Machine Learning\", \"Photography\" },\n    RecentPurchases = new List\u003cPurchase\u003e\n    {\n        new() { Product = \"Camera Lens\", Amount = 450.00m },\n        new() { Product = \"ML Course\", Amount = 99.99m }\n    }\n};\n\n// Serialize to TOON for AI prompt (uses fewer tokens than JSON)\nstring toonContext = ToonSerializer.Serialize(context);\n\n// Use in your LLM prompt\nvar prompt = $@\"\nUser Profile:\n{toonContext}\n\nGenerate personalized product recommendations.\n\";\n\n// Or deserialize back\nvar restored = ToonSerializer.Deserialize\u003cUserContext\u003e(toonContext);\n```\n\n**Output (TOON format - compact, AI-friendly):**\n```toon\nName: Alice\nAge: 28\nInterests[3]: AI, Machine Learning, Photography\nRecentPurchases[2]:\n  - Product: Camera Lens\n    Amount: 450.00\n  - Product: ML Course\n    Amount: 99.99\n```\n\n**Token savings:** ~40% fewer tokens than JSON = lower AI API costs!\n\nThat's it - no configuration, no attributes, just works.\n\n---\n\n## 📚 API Reference\n\nToonNet provides **6 core methods** with familiar System.Text.Json-style naming:\n\n### C# Object Serialization\n\n```csharp\n// Serialize object to TOON string\nstring toon = ToonSerializer.Serialize(myObject);\n\n// Deserialize TOON string to object\nvar obj = ToonSerializer.Deserialize\u003cMyClass\u003e(toonString);\n```\n\n### Format Conversion (String-based)\n\n\u003e **Note:** JSON conversion methods are in `ToonNet.Extensions.Json` package. Add `using ToonNet.Extensions.Json;`\n\n```csharp\n// Convert JSON string to TOON string\nstring toon = ToonConvert.FromJson(jsonString);\n\n// Convert TOON string to JSON string\nstring json = ToonConvert.ToJson(toonString);\n\n// Parse JSON directly to C# object (via TOON)\nvar obj = ToonConvert.DeserializeFromJson\u003cMyClass\u003e(jsonString);\n\n// Serialize C# object directly to JSON\nstring json = ToonConvert.SerializeToJson(myObject);\n```\n\n**Architecture Note:** ToonNet uses a layered approach for JSON interop:\n\n- **`ToonJsonConverter`** - Low-level conversion between `JsonElement` ↔ `ToonDocument`/`ToonValue`. Used internally as the core conversion engine.\n- **`ToonConvert`** - High-level, developer-friendly API (similar to Newtonsoft's `JsonConvert`). Provides simple string-based conversions and internally uses `ToonJsonConverter`.\n\nThis separation of concerns ensures clean architecture: `ToonJsonConverter` handles the conversion logic, while `ToonConvert` provides an ergonomic interface familiar to .NET developers.\n\n### YAML Conversion (Extension Package)\n\n```csharp\nusing ToonNet.Extensions.Yaml;\n\n// YAML string → TOON string\nstring toon = ToonYamlConvert.FromYaml(yamlString);\n\n// TOON string → YAML string\nstring yaml = ToonYamlConvert.ToYaml(toonString);\n```\n\n**Note:** YAML support requires `ToonNet.Extensions.Yaml` package.\n\n**Architecture Note:** Similar to JSON extensions, YAML package uses a layered approach:\n- **`ToonYamlConverter`** - Low-level conversion engine (YAML nodes ↔ ToonDocument)\n- **`ToonYamlConvert`** - High-level string-based API (developer-friendly)\n\n**Complete method reference:**\n\n| Method | Package | Input | Output | Use Case |\n|--------|---------|-------|--------|----------|\n| `Serialize\u003cT\u003e(obj)` | Core | C# Object | TOON string | Save objects as TOON |\n| `Deserialize\u003cT\u003e(toon)` | Core | TOON string | C# Object | Load TOON into objects |\n| `FromJson(json)` | Extensions.Json | JSON string | TOON string | Convert JSON to TOON |\n| `ToJson(toon)` | Extensions.Json | TOON string | JSON string | Convert TOON to JSON |\n| `DeserializeFromJson\u003cT\u003e(json)` | Extensions.Json | JSON string | C# Object | Parse JSON via TOON |\n| `SerializeToJson\u003cT\u003e(obj)` | Extensions.Json | C# Object | JSON string | Export as JSON |\n| `FromYaml(yaml)` | Extensions.Yaml | YAML string | TOON string | Convert YAML to TOON |\n| `ToYaml(toon)` | Extensions.Yaml | TOON string | YAML string | Convert TOON to YAML |\n\n### Async \u0026 Streaming API\n\nFor large datasets (millions of records, database exports, ETL pipelines), ToonNet provides memory-efficient streaming serialization:\n\n```csharp\n// Stream large dataset from database without loading all into memory\nawait ToonSerializer.SerializeStreamAsync(\n    items: dbContext.Users.AsAsyncEnumerable(),\n    filePath: \"users_export.toon\",\n    cancellationToken: cts.Token\n);\n\n// Read back with incremental deserialization\nawait foreach (var user in ToonSerializer.DeserializeStreamAsync\u003cUser\u003e(\"users_export.toon\"))\n{\n    ProcessUser(user);  // Memory-efficient: only one user in memory at a time\n}\n\n// Advanced: Custom separator mode and batch size\nawait ToonSerializer.SerializeStreamAsync(\n    items: GenerateLargeDatasetAsync(),\n    filePath: \"export.toon\",\n    options: null,\n    writeOptions: new ToonMultiDocumentWriteOptions\n    {\n        Mode = ToonMultiDocumentSeparatorMode.ExplicitSeparator,  // Use \"---\" separator\n        DocumentSeparator = \"---\",\n        BatchSize = 100  // Buffer 100 items before writing (improves throughput)\n    },\n    cancellationToken: cts.Token\n);\n```\n\n**Use Cases:**\n- **Database exports** - Stream millions of records without OOM\n- **ETL pipelines** - Process large files incrementally\n- **Log processing** - Parse multi-GB log files\n- **Data migration** - Convert large datasets with minimal memory footprint\n\n**Performance:**\n- **Memory:** Constant O(1) regardless of dataset size (only batch size × item size in memory)\n- **Throughput:** Batched writes reduce I/O overhead by ~2-3x compared to unbuffered\n- **Cancellation:** Full CancellationToken support for long-running operations\n\n📖 **Full API documentation: [API-GUIDE.md](docs/API-GUIDE.md)**\n\n---\n\n## 💡 Examples\n\n### Example 1: AI/LLM Prompt Context (Token Optimization)\n\n```csharp\npublic class CustomerContext\n{\n    public string Name { get; set; }\n    public List\u003cOrder\u003e RecentOrders { get; set; }\n    public List\u003cstring\u003e Preferences { get; set; }\n}\n\npublic class Order\n{\n    public string Id { get; set; }\n    public decimal Total { get; set; }\n    public string Status { get; set; }\n}\n\nvar context = new CustomerContext\n{\n    Name = \"Alice Johnson\",\n    RecentOrders = new List\u003cOrder\u003e\n    {\n        new() { Id = \"ORD-001\", Total = 299.99m, Status = \"Delivered\" },\n        new() { Id = \"ORD-002\", Total = 149.50m, Status = \"Shipped\" }\n    },\n    Preferences = new List\u003cstring\u003e { \"Electronics\", \"Fast Shipping\", \"Eco-Friendly\" }\n};\n\n// Serialize for AI prompt - uses fewer tokens than JSON\nstring promptContext = ToonSerializer.Serialize(context);\n\n// Send to AI API with reduced token usage\nvar aiPrompt = $@\"\nCustomer context:\n{promptContext}\n\nGenerate personalized product recommendations.\n\";\n\n// Result: 40% fewer tokens = 40% lower AI API costs\n```\n\n**Output (compact, AI-friendly):**\n```toon\nName: Alice Johnson\nRecentOrders[2]:\n  - Id: ORD-001\n    Total: 299.99\n    Status: Delivered\n  - Id: ORD-002\n    Total: 149.50\n    Status: Shipped\nPreferences[3]: Electronics, Fast Shipping, Eco-Friendly\n```\n\n---\n\n### Example 2: RAG System (Vector Database Context)\n\n```csharp\npublic class DocumentChunk\n{\n    public string Id { get; set; }\n    public string Content { get; set; }\n    public Dictionary\u003cstring, string\u003e Metadata { get; set; }\n}\n\n// Retrieved chunks from vector database\nvar chunks = new List\u003cDocumentChunk\u003e\n{\n    new()\n    {\n        Id = \"doc_123_chunk_1\",\n        Content = \"ToonNet provides efficient serialization...\",\n        Metadata = new() { [\"source\"] = \"docs\", [\"page\"] = \"1\" }\n    }\n};\n\n// Serialize chunks for LLM context - minimal tokens\nstring context = ToonSerializer.Serialize(chunks);\n\n// Use in RAG prompt with reduced token count\nvar ragPrompt = $\"Context:\\n{context}\\n\\nQuestion: How does ToonNet work?\";\n```\n\n---\n\n### Example 3: Configuration File\n\n```csharp\npublic class DatabaseConfig\n{\n    public string Host { get; set; }\n    public int Port { get; set; }\n    public string Database { get; set; }\n    public bool UseSSL { get; set; }\n}\n\n// Load from file\nvar toonContent = await File.ReadAllTextAsync(\"database.toon\");\nvar config = ToonSerializer.Deserialize\u003cDatabaseConfig\u003e(toonContent);\n\n// Use configuration\nvar connectionString = $\"Host={config.Host};Port={config.Port};Database={config.Database}\";\n```\n\n**database.toon:**\n```toon\nHost: db.example.com\nPort: 5432\nDatabase: myapp_production\nUseSSL: true\n```\n\n---\n\n### Example 4: JSON to TOON Conversion (API Integration)\n\n```csharp\n// Convert existing JSON to token-efficient TOON for AI prompts\nvar jsonResponse = await httpClient.GetStringAsync(\"https://api.example.com/data\");\nvar toonData = ToonConvert.FromJson(jsonResponse);\n\n// Use TOON data in AI prompt (fewer tokens)\nvar aiPrompt = $\"Analyze this data:\\n{toonData}\";\n\n// Or convert back to JSON for other APIs\nvar jsonForExport = ToonConvert.ToJson(toonData);\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselcukgural%2Ftoonnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselcukgural%2Ftoonnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselcukgural%2Ftoonnet/lists"}