YamlDotNet 16.1.1

YamlDotNet

Appveyor NuGet
Build status NuGet

YamlDotNet is a YAML library for netstandard and other .NET runtimes.

YamlDotNet provides low level parsing and emitting of YAML as well as a high level object model similar to XmlDocument. A serialization library is also included that allows to read and write objects from and to YAML streams.

YamlDotNet's conformance with YAML specifications:

YAML Spec YDN Parser YDN Emitter
v1.1
v1.2

What is YAML?

YAML, which stands for "YAML Ain't Markup Language", is described as "a human friendly data serialization standard for all programming languages". Like XML, it allows to represent about any kind of data in a portable, platform-independent format. Unlike XML, it is "human friendly", which means that it is easy for a human to read or produce a valid YAML document.

The YamlDotNet library

The library has now been successfully used in multiple projects and is considered fairly stable. It is compatible with the following runtimes:

  • netstandard 2.0
  • netstandard 2.1
  • .NET 6.0
  • .NET 8.0
  • .NET Framework 4.7

Quick start

Here are some quick samples to get you started which can be viewed in this fiddle.

Serialization from an object to a string

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
...

 var person = new Person
{
    Name = "Abe Lincoln",
    Age = 25,
    HeightInInches = 6f + 4f / 12f,
    Addresses = new Dictionary<string, Address>{
        { "home", new  Address() {
                Street = "2720  Sundown Lane",
                City = "Kentucketsville",
                State = "Calousiyorkida",
                Zip = "99978",
            }},
        { "work", new  Address() {
                Street = "1600 Pennsylvania Avenue NW",
                City = "Washington",
                State = "District of Columbia",
                Zip = "20500",
            }},
    }
};

var serializer = new SerializerBuilder()
    .WithNamingConvention(CamelCaseNamingConvention.Instance)
    .Build();
var yaml = serializer.Serialize(person);
System.Console.WriteLine(yaml);
// Output: 
// name: Abe Lincoln
// age: 25
// heightInInches: 6.3333334922790527
// addresses:
//   home:
//     street: 2720  Sundown Lane
//     city: Kentucketsville
//     state: Calousiyorkida
//     zip: 99978
//   work:
//     street: 1600 Pennsylvania Avenue NW
//     city: Washington
//     state: District of Columbia
//     zip: 20500

Deserialization from a string to an object

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
...

var yml = @"
name: George Washington
age: 89
height_in_inches: 5.75
addresses:
  home:
    street: 400 Mockingbird Lane
    city: Louaryland
    state: Hawidaho
    zip: 99970
";

var deserializer = new DeserializerBuilder()
    .WithNamingConvention(UnderscoredNamingConvention.Instance)  // see height_in_inches in sample yml 
    .Build();

//yml contains a string containing your YAML
var p = deserializer.Deserialize<Person>(yml);
var h = p.Addresses["home"];
System.Console.WriteLine($"{p.Name} is {p.Age} years old and lives at {h.Street} in {h.City}, {h.State}.");
// Output:
// George Washington is 89 years old and lives at 400 Mockingbird Lane in Louaryland, Hawidaho.

More information

More information can be found in the project's wiki.

Installing

Just install the YamlDotNet NuGet package:

PM> Install-Package YamlDotNet

If you do not want to use NuGet, you can download binaries here.

YamlDotNet is also available on the Unity Asset Store.

Contributing

Please read CONTRIBUTING.md for guidelines.

Release notes

Please see the Releases at https://github.com/aaubry/YamlDotNet/releases

Sponsorships

A big shout out to all of our sponsors

AWS

Showing the top 20 packages that depend on YamlDotNet.

Packages Downloads
DeviceDetector.NET
The Universal Device Detection library for .NET that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models. This is a port of the popular PHP device-detector library to C#. For the most part you can just follow the documentation for device-detector with no issue.
12
Elsa.Core
Elsa is a set of workflow libraries and tools that enable super-fast workflowing capabilities in any .NET Core application. This package contains the heart and soul of what makes Elsa tick. It implements most of the abstractions defined in Elsa.Abstractions. If you reference the Elsa package, which is recommended, you don;t have to explicitly reference this package.
12
KubernetesClient
Client library for the Kubernetes open source container orchestrator.
12
KubernetesClient
Client library for the Kubernetes open source container orchestrator.
13
KubernetesClient
Client library for the Kubernetes open source container orchestrator.
15
KubernetesClient.Models
Client library for the Kubernetes open source container orchestrator.
12
KubernetesClient.Models
Client library for the Kubernetes open source container orchestrator.
16
nacos-sdk-csharp.YamlParser
nacos csharp sdk
13
nacos-sdk-csharp.YamlParser
nacos csharp sdk
14
nacos-sdk-csharp.YamlParser
nacos csharp sdk
17
nacos-sdk-csharp.YamlParser
nacos csharp sdk
54
Nuke.Utilities.Text.Yaml
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '011956b31c05f14f3233f6241cd6fbe038824d71' (see contained AppVeyorSettings.json file for build settings).
12
UAParser
A .net wrapper for the ua-parser library
13

.NET Framework 4.7

  • No dependencies.

.NET 6.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET Standard 2.0

  • No dependencies.

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
16.3.0 0 12/23/2024
16.2.1 4 12/01/2024
16.2.0 7 11/23/2024
16.1.3 5 11/24/2024
16.1.2 3 11/24/2024
16.1.1 5 11/20/2024
16.1.0 4 11/24/2024
16.0.0 3 11/24/2024
15.3.0 6 11/24/2024
15.1.6 3 11/26/2024
15.1.4 3 11/24/2024
15.1.2 13 04/24/2024
15.1.1 12 05/01/2024
15.1.0 9 05/07/2024
13.7.1 6 05/27/2024
13.7.0 10 05/19/2024
13.5.2 10 05/19/2024
13.5.1 7 05/29/2024
13.5.0 10 05/04/2024
13.4.0 7 05/19/2024
13.3.1 15 05/14/2024
13.2.0 3 11/20/2024
13.1.1 8 05/13/2024
13.1.0 8 05/23/2024
13.0.2 7 05/07/2024
13.0.1 8 05/26/2024
13.0.0 10 05/24/2024
12.3.1 8 05/24/2024
12.3.0 9 05/06/2024
12.2.1 6 11/24/2024
12.2.0 9 05/06/2024
12.1.0 8 05/16/2024
12.0.2 8 01/18/2023
12.0.1 6 04/28/2024
12.0.0 8 05/27/2024
11.2.0 6 05/15/2024
11.1.1 7 05/21/2024
11.0.1 10 05/18/2024
10.1.0 6 05/09/2024
10.0.0 9 05/01/2022
9.1.4 25 04/21/2022
9.1.0 14 07/12/2022
8.1.2 15 09/29/2022
8.1.0 6 04/30/2022
8.0.0 10 05/02/2022
6.1.2 7 05/14/2024
6.0.0 1,185 05/01/2022
5.4.0 14 04/21/2022
5.1.0 11 05/10/2024