ToonNet.Extensions.Yaml 1.4.0

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

ToonNet.Extensions.Yaml

YAML โ†” TOON format conversion extension

.NET NuGet Downloads Status


๐Ÿ“ฆ What is ToonNet.Extensions.Yaml?

ToonNet.Extensions.Yaml provides seamless bidirectional conversion between YAML and TOON formats:

  • โœ… YAML โ†’ TOON - Convert YAML strings/documents to TOON format
  • โœ… TOON โ†’ YAML - Convert TOON strings/documents to YAML format
  • โœ… YamlDotNet integration - Industry-standard YAML parser
  • โœ… Preserves structure - Round-trip conversions maintain data integrity
  • โœ… Full YAML support - Objects, arrays, scalars, anchors, aliases

Perfect for:

  • โš™๏ธ Configuration Files - Convert YAML configs to TOON format
  • ๐Ÿณ Docker/Kubernetes - Work with container configurations
  • ๐Ÿ”„ CI/CD - Transform GitHub Actions, GitLab CI, etc.
  • ๐Ÿ“‹ OpenAPI/Swagger - Convert API specifications
  • ๐Ÿ”— Cross-format - YAML โ†’ TOON โ†’ JSON workflows

๐Ÿš€ Quick Start

Installation

# Core package (required)
dotnet add package ToonNet.Core

# YAML extension
dotnet add package ToonNet.Extensions.Yaml

Basic Usage - Document Conversion

using ToonNet.Extensions.Yaml;

// YAML โ†’ TOON document
var yaml = """
name: Alice
age: 30
tags:
  - dev
  - admin
settings:
  theme: dark
  notifications: true
""";

var toonDoc = ToonYamlConverter.FromYaml(yaml);

// Access data
var root = (ToonObject)toonDoc.Root;
var name = ((ToonString)root["name"]).Value; // "Alice"
var age = ((ToonNumber)root["age"]).Value;   // 30

// TOON โ†’ YAML document
var yamlOutput = ToonYamlConverter.ToYaml(toonDoc);

String Format Conversion (High-level API)

using ToonNet.Extensions.Yaml;

// YAML โ†’ TOON string conversion
string yamlString = """
name: Alice
age: 30
hobbies:
  - reading
  - coding
""";

string toonString = ToonYamlConvert.FromYaml(yamlString);

// Output (TOON format):
// name: Alice
// age: 30
// hobbies[2]: reading, coding

// TOON โ†’ YAML string conversion
string yamlBack = ToonYamlConvert.ToYaml(toonString);

๐Ÿ“– API Reference

String Format Conversion

// YAML string โ†’ TOON string
string toon = ToonYamlConvert.FromYaml(yamlString);
string toon = ToonYamlConvert.FromYaml(yamlString, options);  // ToonOptions

// TOON string โ†’ YAML string
string yaml = ToonYamlConvert.ToYaml(toonString);

Document Conversion (Low-level)

using ToonNet.Extensions.Yaml;

// YAML string โ†’ ToonDocument
ToonDocument doc = ToonYamlConverter.FromYaml(yamlString);

// ToonDocument โ†’ YAML string
string yaml = ToonYamlConverter.ToYaml(document);

// ToonValue โ†’ YAML string
string yaml = ToonYamlConverter.ToYaml(toonValue);

Architecture Note: ToonNet uses a layered approach for YAML interop:

  • ToonYamlConverter - Low-level conversion between YAML nodes โ†” ToonDocument/ToonValue. Used internally as the core conversion engine.
  • ToonYamlConvert - High-level, developer-friendly API (similar to ToonConvert for JSON). Provides simple string-based conversions and internally uses ToonYamlConverter.

This separation of concerns ensures clean architecture: ToonYamlConverter handles the conversion logic, while ToonYamlConvert provides an ergonomic interface familiar to .NET developers.

Type Support

YAML Type TOON Type Examples
Mapping (object) ToonObject key: value
Sequence (array) ToonArray - item1
Scalar (string) ToonString name: Alice
Scalar (number) ToonNumber age: 30
Scalar (boolean) ToonBoolean enabled: true
Null ToonNull value: null

๐ŸŽฏ Real-World Examples

Example 1: Configuration File Conversion

using ToonNet.Extensions.Yaml;

// Load YAML configuration
string yamlConfig = """
database:
  host: localhost
  port: 5432
  credentials:
    username: admin
    password: secret
logging:
  level: info
  outputs:
    - console
    - file
""";

// Convert to TOON format (more compact)
string toonConfig = ToonYamlConvert.FromYaml(yamlConfig);

// Output (TOON format):
// database:
//   host: localhost
//   port: 5432
//   credentials:
//     username: admin
//     password: secret
// logging:
//   level: info
//   outputs[2]: console, file

// Convert back to YAML if needed
string yamlBack = ToonYamlConvert.ToYaml(toonConfig);

Example 2: Kubernetes Manifest Conversion

using ToonNet.Extensions.Yaml;

// Load Kubernetes YAML
var k8sYaml = """
apiVersion: v1
kind: Service
metadata:
  name: my-service
  labels:
    app: myapp
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
""";

// Convert to TOON (more readable for analysis)
string toonManifest = ToonYamlConvert.FromYaml(k8sYaml);

// Analyze with TOON, then convert back
string modifiedYaml = ToonYamlConvert.ToYaml(toonManifest);

Example 3: Cross-Format Conversion (YAML โ†’ JSON)

using ToonNet.Extensions.Json;
using ToonNet.Extensions.Yaml;

// YAML โ†’ TOON โ†’ JSON
var yaml = """
database:
  host: localhost
  port: 5432
""";

string toon = ToonYamlConvert.FromYaml(yaml);
string json = ToonConvert.ToJson(toon);

// JSON โ†’ TOON โ†’ YAML (reverse)
var jsonStr = """{"name":"Alice","tags":["dev","admin"]}""";
string toonFromJson = ToonConvert.FromJson(jsonStr);
string yamlOutput = ToonYamlConvert.ToYaml(toonFromJson);

Example 4: GitHub Actions Workflow Analysis

using ToonNet.Extensions.Yaml;
using ToonNet.Core.Serialization;

// Load GitHub Actions workflow
var workflowYaml = """
name: CI
on:
  push:
    branches: [ main ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Build
        run: dotnet build
""";

// Convert to TOON format
string toonWorkflow = ToonYamlConvert.FromYaml(workflowYaml);

// Save as TOON for easier reading/editing
File.WriteAllText("workflow.toon", toonWorkflow);

// Convert back when needed
string yamlOutput = ToonYamlConvert.ToYaml(toonWorkflow);

var buildJob = (ToonObject)jobs["build"]; var steps = (ToonArray)buildJob["steps"];

Console.WriteLine($"Workflow has {steps.Items.Count} steps");


---

## โœจ YAML Features Supported

### Boolean Variants
```yaml
# All supported
enabled: true
disabled: false
legacy_yes: yes
legacy_no: no
switch_on: on
switch_off: off

Number Formats

integer: 42
float: 3.14
scientific: 1.5e-10
hex: 0xFF
octal: 0o77

Complex Structures

# Nested objects
user:
  profile:
    settings:
      theme: dark

# Mixed arrays
items:
  - name: Item 1
    price: 9.99
  - name: Item 2
    price: 19.99

# Inline notation
tags: [dev, admin, user]
coords: {x: 10, y: 20}

๐Ÿ”„ Round-Trip Behavior

YAML โ†’ TOON โ†’ YAML conversions preserve structure:

var originalYaml = """
user:
  name: Bob
  roles:
    - admin
    - editor
""";

var toonDoc = ToonYamlConverter.FromYaml(originalYaml);
var roundtripYaml = ToonYamlConverter.ToYaml(toonDoc);

// Structure preserved (formatting may differ)

Note: Comments and anchors/aliases are not preserved (YAML parser limitation).


๐Ÿ”’ Thread-Safety

  • ToonSerializer and YAML conversion methods are safe to call concurrently across threads.
  • Shared metadata/name caches use ConcurrentDictionary for concurrent access.
  • Cache entries are created on demand and retained for the process lifetime (no eviction).
  • Do not mutate a single ToonSerializerOptions instance concurrently across threads.

Core:

Other Extensions:

Web Integration:

Development:


๐Ÿ“š Documentation


๐Ÿงช Testing

# Run YAML conversion tests
cd tests/ToonNet.Tests
dotnet test --filter "FullyQualifiedName~ToonYamlConverter"

# Run specific test categories
dotnet test --filter "Category=YamlConversion"

๐Ÿ“‹ Requirements

  • .NET 8.0 or later
  • ToonNet.Core
  • YamlDotNet 16.3.0+

๐Ÿ“„ License

MIT License - See LICENSE file for details.


๐Ÿค Contributing

Contributions welcome! Please read CONTRIBUTING.md first.


Part of the ToonNet serialization library family.

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 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. 
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
1.4.0 102 2/8/2026
1.3.0 94 2/4/2026
1.2.0 98 2/1/2026
1.1.0 101 1/28/2026
1.0.0 111 1/12/2026

v1.4.0: Updated to support ToonNet.Core 1.4.0 streaming features.