YamlWriterOptions
Definition
Namespace: Corvus.Text.Json.Yaml
Assembly: Corvus.Text.Json.dll
Options for configuring the YAML writer.
public readonly struct YamlWriterOptions
Constructors
| Constructor | Description |
|---|---|
| YamlWriterOptions() | Initializes a new instance of the YamlWriterOptions struct with default values. |
Properties
| Property | Type | Description |
|---|---|---|
| IndentSize | int |
Gets the number of spaces to use for each indentation level. Defaults to 2. |
| SkipValidation | bool |
Gets a value indicating whether to skip structural validation. When false (the default), the writer validates that write operations produce structurally valid YAML. |
Fields
| Field | Type | Description |
|---|---|---|
Default static |
YamlWriterOptions |
Gets the default options: 2-space indentation, structural validation enabled. |
Examples
Configure YAML output formatting with YamlWriterOptions.
using Corvus.Text.Json.Yaml;
var options = new YamlWriterOptions
{
IndentSize = 4, // Default is 2
};
string yaml = YamlDocument.ConvertToYamlString(jsonElement, options);
Default options
The default options use 2-space indentation with validation enabled:
// These are equivalent:
string yaml1 = YamlDocument.ConvertToYamlString(json);
string yaml2 = YamlDocument.ConvertToYamlString(json, YamlWriterOptions.Default);
Skip validation for performance
When you are certain the write calls are well-formed (balanced start/end, correct nesting), disable validation for a small performance gain:
var buffer = new ArrayBufferWriter<byte>();
using var writer = new Utf8YamlWriter(buffer,
new YamlWriterOptions { SkipValidation = true });
Applies To
| Product | Versions |
|---|---|
| .NET | 9, 10 |
| .NET Standard | 2.0, 2.1 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests.
Open an issue