Skip to content

Add ConvertFrom-Yaml and ConvertTo-Yaml functions #2

Description

Why

PowerShell has built-in ConvertFrom-Json / ConvertTo-Json for JSON, but no equivalent for YAML. Scripts and automation that work with YAML configuration files or CI/CD pipelines must rely on external modules or manual string parsing.

What

A ConvertFrom-Yaml function that parses a YAML string into a PowerShell object, and a ConvertTo-Yaml function that serializes a PowerShell object back to a YAML string. Both functions also have a Yml noun alias (ConvertFrom-Yml / ConvertTo-Yml) for discoverability.

The module aligns with YAML 1.2.2 (October 2021) and follows the core schema for scalar resolution. Only the lowercase canonical literals true, false, null, and ~ are recognised as boolean/null types — everything else (True, Yes, On, NULL, etc.) is a plain string.

ConvertFrom-Yaml:

  • Accepts a valid YAML string via pipeline or -InputObject (does not read files or extract markdown frontmatter)
  • Returns a [PSCustomObject] by default, or an [ordered] hashtable with -AsHashtable
  • Supports -NoEnumerate and -Depth (default 1024)
  • Handles standard key-value pairs, nested mappings, and sequences
  • Tolerates document-start (---) and document-end (...) markers

ConvertTo-Yaml:

  • Accepts PowerShell objects, hashtables/ordered dictionaries, and arrays via pipeline or -InputObject
  • Returns a YAML-formatted string
  • Supports -Depth (default 1024), -EnumsAsStrings, -AsArray, and -Indent (default 2)
  • Quotes strings that would otherwise resolve to a core-schema literal or number, so the string type round-trips
  • Produces clean, readable output with proper indentation

Acceptance criteria

  • ConvertFrom-Yaml converts a valid YAML string to a [PSCustomObject] (default) or [ordered] hashtable (-AsHashtable)
  • ConvertTo-Yaml converts a PowerShell object or hashtable to a valid YAML string
  • Round-trip fidelity: $obj | ConvertTo-Yaml | ConvertFrom-Yaml produces an equivalent object
  • Both functions accept pipeline input
  • Scalar resolution matches the YAML 1.2.2 core schema

Note

Advanced YAML features like flow style, block scalars, anchors, aliases, tags, multi-document streams, and !!timestamp parsing are out of scope for this initial version — see #7, #8, #21, #22, #23, #24, #26, and #27. Markdown frontmatter extraction is also out of scope; a separate Markdown module should extract frontmatter and pipe the result into ConvertFrom-Yaml.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions