Styml 0.1.1
dotnet add package Styml --version 0.1.1
NuGet\Install-Package Styml -Version 0.1.1
<PackageReference Include="Styml" Version="0.1.1" />
<PackageVersion Include="Styml" Version="0.1.1" />
<PackageReference Include="Styml" />
paket add Styml --version 0.1.1
#r "nuget: Styml, 0.1.1"
#:package Styml@0.1.1
#addin nuget:?package=Styml&version=0.1.1
#tool nuget:?package=Styml&version=0.1.1
About
Styml is a YAML 1.2 library for .NET with the API of System.Text.Json: YamlSerializer, Utf8YamlReader,
Utf8YamlWriter, YamlDocument, YamlNode, converters and a source generator, in the System.Text.Yaml namespace.
How to use
using System.Text.Yaml;
using System.Text.Yaml.Serialization;
var service = new Service("web", "nginx:1.27", [80, 443], new() { ["TIER"] = "front", ["REPLICAS"] = "3" });
string yaml = YamlSerializer.Serialize(service);
// Name: web
// Image: nginx:1.27
// Ports:
// - 80
// - 443
// Environment:
// TIER: front
// REPLICAS: "3"
Service? back = YamlSerializer.Deserialize<Service>(yaml);
// The same with a source-generated context, for trimming and Native AOT.
string generated = YamlSerializer.Serialize(service, AppYamlContext.Default.Service);
public record Service(string Name, string Image, int[] Ports, Dictionary<string, string> Environment);
[YamlSerializable(typeof(Service))]
internal partial class AppYamlContext : YamlSerializerContext;
Relationship with System.Text.Json
Styml is a clone of System.Text.Json from dotnet/runtime at tag v11.0.0, renamed and adapted to YAML 1.2: the same
API shape (the serializer and its options, the reader, the writer, the DOM, converters, the contract model and the
source generator), in the System.Text.Yaml namespace, plus what YAML adds: anchors and aliases, tags and tag-based
polymorphism, block and flow styles, scalar styles and comments, schemas, merge keys, collection keys and
multi-document streams. It writes block YAML by default and JSON as an option. Styml is an independent project, not a
Microsoft or .NET Foundation product; most of its code is System.Text.Json's, under the MIT license of the .NET
Foundation and its contributors, and the package carries THIRD-PARTY-NOTICES.txt.
Benchmarks
Styml against YamlDotNet 18.1.0, SharpYaml 3.17.0 and VYaml 1.6.1, with System.Text.Json on the same data as JSON as the reference; .NET 11.0.0, Apple M4 Pro, BenchmarkDotNet ShortRun. The first two tables are the Kubernetes manifests of the repository's benchmark corpus (76 KB).
Mean time on k8s-m (microseconds; smaller is better):
| Scenario | Styml | VYaml | SharpYaml | YamlDotNet | System.Text.Json |
|---|---|---|---|---|---|
| Deserialize, source-generated | 290.0 | 370.1 | 1,030.6 | 2,090.7 | 177.7 |
| Deserialize, reflection | 324.0 | n/a | 1,563.8 | 2,733.2 | 198.0 |
| Serialize, source-generated | 53.7 | 100.2 | 182.4 | 1,832.3 | 39.5 |
| Serialize, reused buffer | 50.8 | 100.2 | 182.4 | — | — |
DOM parse (YamlDocument, JsonDocument) |
259.4 | n/a | 1,248.0 | 1,760.4 | 158.3 |
DOM parse, mutable (YamlNode, JsonNode) |
409.4 | n/a | 1,248.0 | 1,760.4 | 344.5 |
| Tokenize | 189.7 | 309.0 | 891.0 | 1,360.2 | 119.1 |
Allocated on k8s-m (smaller is better):
| Scenario | Styml | VYaml | SharpYaml | YamlDotNet | System.Text.Json |
|---|---|---|---|---|---|
| Deserialize, source-generated | 188.8 KB | 185.5 KB | 1.60 MB | 3.39 MB | 188.6 KB |
| Deserialize, reflection | 188.8 KB | n/a | 1.84 MB | 3.60 MB | 188.6 KB |
| Serialize, source-generated | 73.1 KB | 6.2 KB | 25.3 KB | 2.06 MB | 55.0 KB |
| Serialize, reused buffer | 0 B | 6.2 KB | 25.3 KB | — | — |
DOM parse (YamlDocument, JsonDocument) |
72 B | n/a | 1.83 MB | 2.75 MB | 72 B |
DOM parse, mutable (YamlNode, JsonNode) |
815.9 KB | n/a | 1.83 MB | 2.75 MB | 809.5 KB |
| Tokenize | 0 B | 1.1 KB | 1.26 MB | 1.78 MB | 0 B |
Time against Styml's, the geometric mean over the five documents (below 1 is faster than Styml):
| Scenario | Styml | VYaml | SharpYaml | YamlDotNet | System.Text.Json |
|---|---|---|---|---|---|
| Deserialize, source-generated | 1.00× | 1.42× | 3.66× | 7.26× | 0.65× |
| Deserialize, reflection | 1.00× | n/a | 4.57× | 8.62× | 0.62× |
| Serialize, source-generated | 1.00× | 1.76× | 2.92× | 28.06× | 0.66× |
| Serialize, reused buffer | 1.00× | 1.89× | 3.15× | — | — |
DOM parse (YamlDocument, JsonDocument) |
1.00× | n/a | 4.86× | 6.99× | 0.59× |
DOM parse, mutable (YamlNode, JsonNode) |
1.00× | n/a | 2.76× | 3.97× | 0.78× |
| Tokenize | 1.00× | 1.79× | 4.95× | 7.43× | 0.65× |
More
The repository's README covers every option and behaviour with tested samples, YAML conformance and the charts: https://github.com/sebastienros/styml. The options reference: https://github.com/sebastienros/styml/blob/main/docs/options.md.
| 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 was computed. 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. net11.0 is compatible. |
| .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
- Microsoft.Bcl.AsyncInterfaces (>= 11.0.0)
- System.Buffers (>= 4.6.1)
- System.IO.Pipelines (>= 11.0.0)
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Text.Encodings.Web (>= 11.0.0)
- System.Threading.Tasks.Extensions (>= 4.6.3)
-
net10.0
- System.IO.Pipelines (>= 11.0.0)
- System.Text.Encodings.Web (>= 11.0.0)
-
net11.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.