SharpYaml 3.10.2
Prefix ReservedSee the version list below for details.
dotnet add package SharpYaml --version 3.10.2
NuGet\Install-Package SharpYaml -Version 3.10.2
<PackageReference Include="SharpYaml" Version="3.10.2" />
<PackageVersion Include="SharpYaml" Version="3.10.2" />
<PackageReference Include="SharpYaml" />
paket add SharpYaml --version 3.10.2
#r "nuget: SharpYaml, 3.10.2"
#:package SharpYaml@3.10.2
#addin nuget:?package=SharpYaml&version=3.10.2
#tool nuget:?package=SharpYaml&version=3.10.2
SharpYaml

<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 withYamlSerializer,YamlSerializerOptions, and resolver-based metadata (IYamlTypeInfoResolver). See the migration guide for details.
✨ Features
System.Text.Json-style API: familiar surface withYamlSerializer,YamlSerializerOptions,YamlTypeInfo<T>- YAML 1.2 Core Schema: spec-compliant parsing with configurable schema (Failsafe, JSON, Core, Extended)
- Source generation: NativeAOT / trimming friendly via
YamlSerializerContextwith[YamlSerializable]roots System.Text.Jsonattribute 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 [YamlSerializable] roots:
using SharpYaml.Serialization;
[YamlSerializable(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);
Cross-Project Polymorphism
When a base type lives in one assembly and the derived types live in another, you can register mappings where the composition root already references both sides.
Reflection-based serialization can register mappings at runtime:
var options = new YamlSerializerOptions
{
PolymorphismOptions = new YamlPolymorphismOptions
{
DerivedTypeMappings =
{
[typeof(Animal)] =
[
new YamlDerivedType(typeof(Dog), "dog") { Tag = "!dog" },
new YamlDerivedType(typeof(Cat), "cat") { Tag = "!cat" },
]
}
}
};
Source-generated contexts can register the same relationship at compile time:
[YamlSerializable(typeof(Zoo))]
[YamlDerivedTypeMapping(typeof(Animal), typeof(Dog), "dog", Tag = "!dog")]
[YamlDerivedTypeMapping(typeof(Animal), typeof(Cat), "cat", Tag = "!cat")]
internal partial class ZooYamlContext : YamlSerializerContext { }
Context-level mappings are additive to [YamlDerivedType] and JsonDerivedType attributes. Attribute-based entries win when the same derived type or discriminator is registered more than once.
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 ~6x 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.8655/25H2/2025Update/HudsonValley2)
AMD Ryzen 9 9950X 4.30GHz, 1 CPU, 32 logical and 16 physical cores
.NET SDK 10.0.301
[Host] : .NET 10.0.9 (10.0.9, 10.0.926.27113), X64 RyuJIT x86-64-v4
DefaultJob : .NET 10.0.9 (10.0.9, 10.0.926.27113), X64 RyuJIT x86-64-v4
| Type | Method | Categories | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PocoBenchmarks | SharpYaml_Deserialize_Poco | Deserialize_Poco | 1,341.5 μs | 3.07 μs | 2.56 μs | 1,342.5 μs | 1.00 | 0.00 | 119.1406 | 70.3125 | - | 1947.94 KB | 1.00 |
| PocoBenchmarks | YamlDotNet_Deserialize_Poco | Deserialize_Poco | 2,764.9 μs | 42.75 μs | 35.70 μs | 2,765.6 μs | 2.06 | 0.03 | 250.0000 | 218.7500 | - | 4135.91 KB | 2.12 |
| GenericSerializationBenchmarks | SharpYaml_Serialize_GenericDictionary | Serialize_GenericDictionary | 326.7 μs | 6.45 μs | 11.95 μs | 318.7 μs | 1.00 | 0.05 | 83.0078 | 83.0078 | 83.0078 | 303.42 KB | 1.00 |
| GenericSerializationBenchmarks | YamlDotNet_Serialize_GenericDictionary | Serialize_GenericDictionary | 2,062.5 μs | 4.53 μs | 3.54 μs | 2,062.0 μs | 6.32 | 0.23 | 152.3438 | 148.4375 | 74.2188 | 2579.25 KB | 8.50 |
| PocoBenchmarks | SharpYaml_Serialize_Poco | Serialize_Poco | 354.5 μs | 1.01 μs | 0.84 μs | 354.3 μs | 1.00 | 0.00 | 83.0078 | 83.0078 | 83.0078 | 330.99 KB | 1.00 |
| PocoBenchmarks | YamlDotNet_Serialize_Poco | Serialize_Poco | 2,608.8 μs | 35.76 μs | 31.70 μs | 2,608.6 μs | 7.36 | 0.09 | 125.0000 | 62.5000 | 62.5000 | 2529.24 KB | 7.64 |
| SourceGeneratedBenchmarks | SharpYaml_SourceGenerated_Serialize | Serialize_SourceGenerated | 296.2 μs | 0.67 μs | 0.60 μs | 296.4 μs | 1.00 | 0.00 | 83.0078 | 83.0078 | 83.0078 | 295.37 KB | 1.00 |
| SourceGeneratedBenchmarks | YamlDotNet_StaticGenerator_Serialize | Serialize_SourceGenerated | 2,120.9 μs | 5.14 μs | 4.29 μs | 2,121.4 μs | 7.16 | 0.02 | 152.3438 | 74.2188 | 74.2188 | 2404.09 KB | 8.14 |
| GenericSerializationBenchmarks | SharpYaml_Serialize_StringList | Serialize_StringList | 433.8 μs | 0.98 μs | 0.82 μs | 433.9 μs | 1.00 | 0.00 | 99.6094 | 99.6094 | 99.6094 | 329.25 KB | 1.00 |
| GenericSerializationBenchmarks | YamlDotNet_Serialize_StringList | Serialize_StringList | 2,637.8 μs | 10.95 μs | 9.14 μs | 2,638.3 μs | 6.08 | 0.02 | 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 | Versions 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. |
-
.NETStandard 2.0
- System.Buffers (>= 4.6.1)
- System.Collections.Immutable (>= 9.0.0)
- System.Text.Json (>= 10.0.3)
-
net10.0
- No dependencies.
-
net8.0
- System.Collections.Immutable (>= 9.0.0)
NuGet packages (53)
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. |
|
|
Microsoft.OpenApi.YamlReader
OpenAPI.NET Reader for YAML documents |
|
|
WorkflowCore.DSL
DSL extenstion for Workflow Core provding support for JSON and YAML workflow definitions. |
|
|
ITGlobal.MarkDocs.Markdown
ASP.NET Core extensible and embeddable documentation engine |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.13.0 | 9 | 7/10/2026 |
| 3.12.0 | 5,094 | 7/2/2026 |
| 3.11.0 | 10,862 | 6/24/2026 |
| 3.10.2 | 973 | 6/22/2026 |
| 3.10.1 | 260 | 6/22/2026 |
| 3.10.0 | 12,177 | 6/10/2026 |
| 3.9.0 | 2,514 | 6/7/2026 |
| 3.8.0 | 4,403 | 5/28/2026 |
| 3.7.2 | 560 | 5/28/2026 |
| 3.7.1 | 35,709 | 4/26/2026 |
| 3.7.0 | 42,500 | 3/29/2026 |
| 3.6.0 | 626 | 3/29/2026 |
| 3.5.0 | 6,949 | 3/24/2026 |
| 3.4.0 | 6,959 | 3/11/2026 |
| 3.3.0 | 1,081 | 3/10/2026 |
| 3.2.0 | 1,693 | 3/6/2026 |
| 3.1.0 | 1,367 | 3/4/2026 |
| 3.0.0 | 1,792 | 3/1/2026 |
| 2.1.4 | 704,442 | 10/24/2025 |
| 2.1.3 | 4,668,140 | 6/12/2025 |