GuideReference

Options reference

The options and attributes Styml adds to System.Text.Json's for YAML, with their defaults, and the System.Text.Json options that behave differently.

Every System.Text.Json option keeps its meaning in Styml, under the same name with Yaml in place of Json: see the API reference of YamlSerializerOptions for all of them. This page lists what Styml adds for YAML, by type, with each default, and the few System.Text.Json options that changed. The guide shows each one at work: Writing YAML, Scalar styles, Schemas, Reading YAML, References and Polymorphism.

The playground lets you try the reading and writing options on your own YAML.

YAML optionsLink to this heading

YamlSerializerOptionsLink to this heading

Member Default Effect
WriteStyle Block Block YAML, or JsonCompatible JSON.
IndentSequences false Indents a sequence under a key (key:\n - a) instead of writing it at the key's column.
ExpandSequenceItems false Starts a collection that is a sequence item on the line after its dash.
MaxLineWidth 0 (none) Folds plain and double-quoted scalars at a space past this width, and continues a flow collection on a new line.
MultiLineStringStyle None (literal) The style of a string with a line break: Literal, Folded or DoubleQuoted.
DefaultScalarStyle None The style of every other string value: Plain, SingleQuoted, DoubleQuoted, Literal or Folded, where it can hold the text.
QuoteForLenientReaders false Also quotes strings that some readers misread although no YAML standard resolves them.
MappingOrder Declaration Sorted writes members by [YamlPropertyOrder], then by name, ordinal.
IgnoreSourceStyles false Writes a YamlDocument, a YamlElement or a YamlNode in the options' styles rather than its source's.
Schema Core How plain scalars resolve when read: Core (YAML 1.2), Yaml11, Json or Failsafe.
AcceptLenientScalars false Typed reads also accept the scalars YamlDotNet or SharpYaml resolve although no standard does (quoted numbers, booleans in any case, padded dates).
DuplicateKeyHandling Error What a repeated mapping key does: Error, LastWins or FirstWins.
MaxAliasExpansion 0 The most nodes aliases may copy in one deserialization; 0 allows 10,000 nodes, or as many as the bytes read when that is more.
ResolveMergeKeys false Merges a << key's mappings into the mapping that holds it.
DisallowImplicitCollectionKeys false Refuses a flow collection as an implicit key, so a stream yields each element as soon as it is complete.
TagMappings empty The tags that select a type when reading, and that the type writes: an explicit allow-list.

YamlWriterOptionsLink to this heading

Member Default Effect
Style Block Block YAML, or JsonCompatible JSON.
IndentSequences false As on YamlSerializerOptions.
ExpandSequenceItems false As on YamlSerializerOptions.
MaxLineWidth 0 As on YamlSerializerOptions.
MultiLineStringStyle None As on YamlSerializerOptions.
DefaultScalarStyle None As on YamlSerializerOptions, below a WriteScalarStyle hint.
QuoteForLenientReaders false As on YamlSerializerOptions.
IgnoreSourceStyles false As on YamlSerializerOptions.

YamlReaderOptionsLink to this heading

Member Default Effect
Schema Core How plain scalars resolve into token types.
AcceptLenientScalars false As on YamlSerializerOptions, for the typed Get and TryGet methods.
DisallowImplicitCollectionKeys false As on YamlSerializerOptions.

YamlDocumentOptionsLink to this heading

Member Default Effect
Schema Core How plain scalars resolve in the document.
DuplicateKeyHandling Error Under LastWins and FirstWins the document keeps every entry, and a lookup returns the last or the first match.
MaxAliasExpansion 0 The most nodes copying aliases may add when the document's nodes are copied; 0 allows ten times the document's own node count, or 10,000, whichever is larger.
ResolveMergeKeys false As on YamlSerializerOptions.

YamlSourceGenerationOptionsAttributeLink to this heading

The defaults of a source-generated context's options, as on YamlSerializerOptions: WriteStyle, IndentSequences, ExpandSequenceItems, MaxLineWidth, MultiLineStringStyle, DefaultScalarStyle, QuoteForLenientReaders, MappingOrder, IgnoreSourceStyles, Schema, AcceptLenientScalars, DuplicateKeyHandling, MaxAliasExpansion, ResolveMergeKeys and DisallowImplicitCollectionKeys. [YamlTagMapping] on the context fills TagMappings.

YamlPolymorphismOptionsLink to this heading

Member Default Effect
DiscriminatorStyle Property How a hierarchy writes its derived types: Property ($type), Tag or Both.

YamlPolymorphicAttributeLink to this heading

Member Default Effect
DiscriminatorStyle Property As on YamlPolymorphismOptions.

YamlDerivedTypeAttributeLink to this heading

Member Default Effect
Tag ! and the discriminator The tag the derived type writes and is read from under Tag and Both.

YamlTagMappingAttributeLink to this heading

Member Effect
Tag The tag, local (!dog) or a global URI.
Type The type it reads into and that writes it.

YamlScalarStyleAttributeLink to this heading

Member Effect
Style The style of the member's string value, as DefaultScalarStyle gives it to every other one.

YamlCommentAttributeLink to this heading

Member Effect
Comment A comment written on the lines above the member, in block style.

YamlIgnoreConditionLink to this heading

Value Effect
WhenWritingEmptyCollection Leaves out a null value or an empty collection, as YamlDotNet's OmitNull \| OmitEmptyCollections.

ReferenceHandlerLink to this heading

Value Effect
Preserve Writes an anchor for each object or collection referenced more than once, and aliases for the references.
PreserveAll Writes an anchor for every object and collection.

System.Text.Json options that changedLink to this heading

Option In Styml
WriteIndented Formats the JSON-compatible style; block YAML is always written on lines.
IndentSize, IndentCharacter Block style needs an indent of at least 2 spaces; a tab is refused.
AllowTrailingCommas Kept for source compatibility; it changes nothing, since YAML flow collections accept one trailing comma.
ReadCommentHandling, CommentHandling # comments are always read, and skipped unless the reader is asked for them. Disallow, the default, is standard YAML: // and /* */ are not comments, and read as text. Skip skips JSON comments, and on the reader Allow returns them as Comment tokens, as System.Text.Json does: inside flow collections ([ ], { }) and before and after the root node, never inside a block collection. A JSON comment starts where a token may start, after white space, or directly after a JSON number, true, false or null, so [http://x, a//b] keeps its text.
AllowDuplicateProperties A view of DuplicateKeyHandling: true selects LastWins, false Error.
ReferenceHandler Writes YAML anchors and aliases in block style; $id, $ref and $values in the JSON-compatible style.
IgnoreNullValues, AddContext Removed (obsolete in System.Text.Json).

Esc to close