oneyaml for C#
Lossless, comment-preserving editing and a System.Text.Json-style serializer for YAML 1.2, in one .NET package.
A quick look
Edit a document in place, keeping its comments, block scalars and layout, then bind the same text to a record with the serializer.
Getting started// The lossless document: edit in place using var doc = YamlDocument.Parse(src); doc.Root["replicas"] = 3; // Only the 2 changes; comments stay. // Typed reads, as with System.Text.Json var cfg = YamlSerializer.Deserialize<Config>(src);
The package
- Packages
OneYaml1.2.1, withOneYaml.Compat.YamlDotNetandOneYaml.Compat.SharpYamlat the same version. - Serializer
Options, naming policies, converters, polymorphism and the System.Text.Json attributes, with a source generator in the package for trimmed and native AOT apps.
- Edits
YamlDocumentchanges only what you touch, in the old value’s style. JSON Patch and merge patch apply the same way. - Migration
Compatibility packages for YamlDotNet and SharpYaml cover the common serializer and model calls, with every difference listed.
- Conformance
Checked against the full yaml-test-suite and the oneyaml conformance kit, with every deviation listed.
- Safety
No unsafe code. Depth, alias expansion and integer size are bounded by default;
YamlLimits.Untrustedbounds the rest. - .NET
.NET 8 and .NET 10. MIT or Apache-2.0.