SharpYaml 3.0.0

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

SharpYaml ci NuGet

<img align="right" width="256px" height="256px" src="https://raw.githubusercontent.com/xoofx/SharpYaml/master/img/SharpYaml.png">

SharpYaml is a high-performance .NET YAML parser, emitter, and object serializer - NativeAOT ready.

Note: SharpYaml v3 is a major redesign with breaking changes from v2. It uses a System.Text.Json-style API with YamlSerializer, YamlSerializerOptions, and resolver-based metadata (IYamlTypeInfoResolver). See the migration guide for details.

✨ Features

  • System.Text.Json-style API: familiar surface with YamlSerializer, YamlSerializerOptions, YamlTypeInfo<T>
  • YAML 1.2 Core Schema: spec-compliant parsing with configurable schema (Failsafe, JSON, Core, Extended)
  • Source generation: NativeAOT / trimming friendly via YamlSerializerContext - reuses [JsonSerializable] attributes
  • System.Text.Json attribute interop: reuse [JsonPropertyName], [JsonIgnore], [JsonPropertyOrder], [JsonConstructor]
  • Flexible I/O: serialize/deserialize from string, ReadOnlySpan<char>, TextReader, TextWriter
  • Rich options: naming policies, indent control, null handling, duplicate key behavior, reference handling, polymorphism
  • Low-level access: full scanner, parser, emitter, and syntax tree APIs for advanced YAML processing
  • NativeAOT and trimming oriented (IsAotCompatible, IsTrimmable)

📐 Requirements

SharpYaml targets net8.0, net10.0, and netstandard2.0.

  • Consuming the NuGet package works on any runtime that supports netstandard2.0 (including .NET Framework) or modern .NET (net8.0+).
  • Building SharpYaml from source requires the .NET 10 SDK (C# 14).

📦 Install

dotnet add package SharpYaml

SharpYaml ships the source generator in-package (analyzers/dotnet/cs) - no extra package needed.

🚀 Quick Start

using SharpYaml;

// Serialize
var yaml = YamlSerializer.Serialize(new { Name = "Ada", Age = 37 });

// Deserialize
var person = YamlSerializer.Deserialize<Person>(yaml);

Options

var options = new YamlSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    WriteIndented = true,
    IndentSize = 4,
    DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingNull,
};

var yaml = YamlSerializer.Serialize(config, options);
var model = YamlSerializer.Deserialize<MyConfig>(yaml, options);

By default, PropertyNamingPolicy is null, meaning CLR member names are used as-is for YAML mapping keys (same default as System.Text.Json).

Source Generation

Declare a context with [JsonSerializable] roots:

using System.Text.Json.Serialization;
using SharpYaml.Serialization;

[JsonSerializable(typeof(MyConfig))]
internal partial class MyYamlContext : YamlSerializerContext { }

Then consume generated metadata:

var context = MyYamlContext.Default;
var yaml = YamlSerializer.Serialize(config, context.MyConfig);
var roundTrip = YamlSerializer.Deserialize(yaml, context.MyConfig);

Reflection Control

Reflection fallback can be disabled globally before first serializer use:

AppContext.SetSwitch("SharpYaml.YamlSerializer.IsReflectionEnabledByDefault", false);

When reflection is disabled, POCO/object mapping requires metadata (use generated YamlTypeInfo<T>, the overloads that accept a YamlSerializerContext, or pass MyYamlContext.Default.Options to an options-based overload). Primitive scalars and untyped containers (object, Dictionary<string, object>, List<object>, object[]) still work without reflection.

When publishing with NativeAOT (PublishAot=true), the SharpYaml NuGet package disables reflection-based serialization by default. You can override the default by setting the following MSBuild property in your app project:

<PropertyGroup>
  <SharpYamlIsReflectionEnabledByDefault>true</SharpYamlIsReflectionEnabledByDefault>
</PropertyGroup>

🚀 Benchmarks

In the included benchmarks, SharpYaml is typically ~2x to ~15x faster than YamlDotNet and uses ~2x to ~9x less memory allocations, depending on the scenario (POCO vs generic vs source-generated).

BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.7840/25H2/2025Update/HudsonValley2)
AMD Ryzen 9 7950X 4.50GHz, 1 CPU, 32 logical and 16 physical cores
.NET SDK 10.0.103
  [Host]     : .NET 10.0.3 (10.0.3, 10.0.326.7603), X64 RyuJIT x86-64-v4
  DefaultJob : .NET 10.0.3 (10.0.3, 10.0.326.7603), X64 RyuJIT x86-64-v4
Type Method Categories Mean Error StdDev Ratio RatioSD Gen0 Gen1 Gen2 Allocated Alloc Ratio
PocoBenchmarks SharpYaml_Deserialize_Poco Deserialize_Poco 1,565.4 us 28.06 us 26.25 us 1.00 0.02 109.3750 68.3594 - 1803.33 KB 1.00
PocoBenchmarks YamlDotNet_Deserialize_Poco Deserialize_Poco 3,130.9 us 49.63 us 46.42 us 2.00 0.04 250.0000 175.7813 - 4135.78 KB 2.29
GenericSerializationBenchmarks SharpYaml_Serialize_GenericDictionary Serialize_GenericDictionary 225.2 us 4.41 us 4.13 us 1.00 0.03 83.2520 83.2520 83.2520 277.02 KB 1.00
GenericSerializationBenchmarks YamlDotNet_Serialize_GenericDictionary Serialize_GenericDictionary 2,680.6 us 4.37 us 3.65 us 11.91 0.21 152.3438 148.4375 74.2188 2579.25 KB 9.31
PocoBenchmarks SharpYaml_Serialize_Poco Serialize_Poco 252.0 us 2.06 us 1.72 us 1.00 0.01 83.0078 83.0078 83.0078 292.92 KB 1.00
PocoBenchmarks YamlDotNet_Serialize_Poco Serialize_Poco 3,396.3 us 46.01 us 43.04 us 13.48 0.19 152.3438 148.4375 74.2188 2529.12 KB 8.63
SourceGeneratedBenchmarks SharpYaml_SourceGenerated_Serialize Serialize_SourceGenerated 201.1 us 3.27 us 3.36 us 1.00 0.02 83.2520 83.2520 83.2520 268.92 KB 1.00
SourceGeneratedBenchmarks YamlDotNet_StaticGenerator_Serialize Serialize_SourceGenerated 2,620.2 us 20.60 us 18.26 us 13.03 0.23 152.3438 74.2188 74.2188 2404.09 KB 8.94
GenericSerializationBenchmarks SharpYaml_Serialize_StringList Serialize_StringList 217.9 us 2.46 us 2.30 us 1.00 0.01 99.8535 99.8535 99.8535 329.25 KB 1.00
GenericSerializationBenchmarks YamlDotNet_Serialize_StringList Serialize_StringList 3,269.2 us 13.52 us 12.64 us 15.01 0.16 218.7500 214.8438 109.3750 3019.75 KB 9.17

📖 Documentation

Full documentation is available at https://xoofx.github.io/SharpYaml.

🪪 License

This software is released under the MIT license.

🤗 Author

Alexandre Mutel aka xoofx.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (48)

Showing the top 5 NuGet packages that depend on SharpYaml:

Package Downloads
Microsoft.OpenApi.Readers

OpenAPI.NET Readers for JSON and YAML documents

WireMock.Net.OpenApiParser

An OpenApi (swagger) parser to generate MappingModel or mapping.json file.

WorkflowCore.DSL

DSL extenstion for Workflow Core provding support for JSON and YAML workflow definitions.

Microsoft.OpenApi.YamlReader

OpenAPI.NET Reader for YAML documents

ITGlobal.MarkDocs.Markdown

ASP.NET Core extensible and embeddable documentation engine

GitHub repositories (17)

Showing the top 17 popular GitHub repositories that depend on SharpYaml:

Repository Stars
chocolatey/choco
Chocolatey - the package manager for Windows
danielgerlag/workflow-core
Lightweight workflow engine for .NET Standard
ashmind/SharpLab
.NET language playground
wiremock/WireMock.Net
WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on WireMock Java, but extended with more functionality.Full documentation can be found at https://wiremock.org/dotnet/.
microsoft/OpenAPI.NET
The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
Cinchoo/ChoETL
ETL framework for .NET (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
danielgerlag/conductor
Distributed workflow server
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
sonatype-nexus-community/DevAudit
Open-source, cross-platform, multi-purpose security auditing tool
microsoft/OpenAPI.NET.CSharpAnnotations
Generates OpenAPI Document from C# Annotations
842549829/Panda
Abp.vNext + EF Core The microservices Open source framework project supports the implementation of message push workflow certification centers based on OAuth2.0
kallex/PromDapter
Prometheus CzAdapter
opensearch-project/opensearch-net
OpenSearch .NET Client
solliancenet/tech-immersion-data-ai
xoofx/AsmArm64
The most powerful ARM 64 (v8, v9) Assembler / Disassembler for .NET
lunet-io/lunet
A fast, modular static website generator
microsoft/botframework-components
The repository for components built by Microsoft for the Azure Bot Framework.
Version Downloads Last Updated
3.0.0 20 3/1/2026
2.1.4 135,915 10/24/2025
2.1.3 812,907 6/12/2025
2.1.2 35,296 5/23/2025
2.1.1 13,854,906 2/13/2024
2.1.0 9,548,266 8/12/2022
2.0.0 24,224 7/4/2022
1.9.2 695,800 6/15/2022
1.9.1 257,907 5/8/2022
1.9.0 918,468 3/6/2022
1.8.0 174,551 9/16/2021
1.6.6 617,296 2/22/2020
1.6.5 21,757,828 2/14/2019
1.6.4 92,710 7/9/2018
1.6.3 51,376 4/22/2018
1.6.2 28,630 11/19/2017
1.6.2-pre027 2,170 11/19/2017
1.6.1 2,762,563 4/4/2017
1.6.1-pre010 1,936 4/4/2017
1.6.0 3,252 4/3/2017
Loading failed