Yamlify 1.5.0

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

Yamlify

<p align="center"> <i>✨ 100% vibe engineered ✨</i> </p>

A high-performance, AOT-compatible YAML 1.2 serializer for .NET.

NuGet License: MIT

Features

  • 100% AOT-compatible - No reflection at runtime, works with Native AOT, iOS, and WebAssembly
  • Source-generated serialization - Type-safe serialization code generated at compile time
  • Zero-allocation parsing - Uses ref struct and Span<T> for allocation-free operation
  • YAML 1.2 compliant - Full support for the latest YAML specification
  • Familiar API - Similar patterns to System.Text.Json

YAML Compliance

Full YAML 1.2 support. Tested against the official yaml-test-suite (v2022-01-17).

Installation

dotnet add package Yamlify

Quick Start

1. Define your types and context

using Yamlify.Serialization;

// Your data types
public class Person
{
    public string Name { get; set; } = "";
    public int Age { get; set; }
    public List<string>? Tags { get; set; }
}

// Register types for source generation
[YamlSerializable(typeof(Person))]
public partial class MySerializerContext : YamlSerializerContext { }

2. Serialize to YAML

var person = new Person
{
    Name = "John Doe",
    Age = 30,
    Tags = ["developer", "yaml"]
};

// Option A: Pass context explicitly
string yaml = YamlSerializer.Serialize(person, MySerializerContext.Default.Person);

// Option B: Set default resolver once, use simple API everywhere
YamlSerializerOptions.Default.TypeInfoResolver = MySerializerContext.Default;
string yaml = YamlSerializer.Serialize(person);  // No context needed!

// Output:
// name: John Doe
// age: 30
// tags:
//   - developer
//   - yaml

3. Deserialize from YAML

var yaml = """
    name: Jane Smith
    age: 25
    tags:
      - designer
    """;

// With explicit context
var person = YamlSerializer.Deserialize<Person>(yaml, MySerializerContext.Default.Person);

// Or with default resolver configured
var person = YamlSerializer.Deserialize<Person>(yaml);

Serialization Options

var options = new YamlSerializerOptions
{
    // Property naming
    PropertyNamingPolicy = YamlNamingPolicy.CamelCase,  // or SnakeCase, KebabCase (default)
    
    // Null handling
    IgnoreNullValues = true,        // Omit properties with null values
    IgnoreEmptyObjects = true,      // Omit nested objects where all nullable props are null
    
    // Circular references
    ReferenceHandler = ReferenceHandler.IgnoreCycles,
    
    // Formatting
    WriteIndented = true,
    IndentSize = 2
};

var yaml = YamlSerializer.Serialize(person, MySerializerContext.Default.Person, options);

See the Serialization Guide for more details.

Attributes

Property Customization

public class Product
{
    [YamlPropertyName("product-id")]
    public string Id { get; set; } = "";
    
    [YamlIgnore]
    public string InternalCode { get; set; } = "";
    
    [YamlPropertyOrder(1)]
    public string Name { get; set; } = "";
    
    [YamlPropertyOrder(2)]
    public decimal Price { get; set; }
}

Polymorphic Serialization

Yamlify supports polymorphic type hierarchies with type discriminators:

[YamlPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[YamlDerivedType(typeof(Dog), "dog")]
[YamlDerivedType(typeof(Cat), "cat")]
public abstract class Animal
{
    public string Name { get; set; } = "";
}

public class Dog : Animal { public string Breed { get; set; } = ""; }
public class Cat : Animal { public bool IsIndoor { get; set; } }
$type: dog
name: Buddy
breed: Golden Retriever

Sibling Discrimination

For configurations where the type is determined by a sibling property (e.g., an enum):

public class ConfigItem
{
    public string Name { get; set; } = "";
    public ValueType Type { get; set; }
    
    [YamlSiblingDiscriminator(nameof(Type))]
    [YamlDiscriminatorMapping(nameof(ValueType.String), typeof(StringValue))]
    [YamlDiscriminatorMapping(nameof(ValueType.Integer), typeof(IntegerValue))]
    public ConfigValue? Value { get; set; }
}

See the Serialization Guide for complete polymorphism documentation.

Low-Level Reader API

For advanced scenarios, use the low-level reader directly:

using Yamlify.Core;

var yaml = """
    name: John
    age: 30
    """u8;

var reader = new Utf8YamlReader(yaml);
while (reader.Read())
{
    Console.WriteLine($"{reader.TokenType}: {reader.GetString()}");
}

Documentation

Building & Testing

Clone the repository

# Clone with submodules (recommended)
git clone --recurse-submodules https://github.com/SwissLife-OSS/yamlify.git

# Or if already cloned, initialize submodules
git submodule update --init --recursive

Run tests

dotnet test

The test suite includes the official yaml-test-suite as a git submodule for YAML compliance testing.

License

MIT License - see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET 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.
  • net10.0

    • No dependencies.

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.5.0 46 1/12/2026
1.4.1 48 1/12/2026
1.4.0 48 1/9/2026
1.3.1 36 1/9/2026
1.3.0 44 1/9/2026
1.2.3 107 1/5/2026
1.2.2 93 1/5/2026
1.2.1 89 1/5/2026
1.2.0 85 1/5/2026
1.1.0 86 1/1/2026