Scripts that work with layered configuration — defaults + environment overrides, base + local — need to merge TOML documents without writing ad-hoc hashtable loops. Merge-Toml combines two or more TOML documents into one, mirroring the pattern of Merge-Hashtable in the PSModule ecosystem.
Request
Desired capability
# Merge two strings
Merge-Toml -BaseObject $defaults -OverrideObject $overrides
# Merge files
Merge-Toml -Path base.toml -Override override.toml
# Pipeline: merge a stream of documents
$docs | Merge-Toml
Parameters
| Parameter |
Description |
-BaseObject |
Base TOML string or TomlDocument (default parameter set) |
-OverrideObject |
Override TOML string or TomlDocument applied on top of base |
-Path |
File path(s) to merge in order (first = base, rest = overrides) |
-LiteralPath |
Literal file path(s), same order semantics |
-Strategy |
Merge strategy: LastWins (default), FirstWins, ErrorOnConflict |
Merge semantics
- Scalar keys: controlled by
-Strategy (default: last value wins)
- Nested tables: deep-merged recursively
- Arrays of tables (
[[...]]): appended in order
- Inline arrays: treated as scalars (replaced, not merged)
- Output is always a
[string] (canonical TOML)
Acceptance criteria
Merge-Toml $a $b produces TOML containing all keys from both; overlapping scalars obey -Strategy
- Deep tables are recursively merged
- Arrays of tables are concatenated
- All output is parseable by
ConvertFrom-Toml
-ErrorOnConflict throws on any duplicate scalar key
Technical decisions
Implementation: Parse both inputs with ConvertFrom-Toml, walk the resulting ordered dictionaries recursively with a private helper Merge-TomlTableObject, then re-serialize with ConvertTo-Toml.
Function placement: src/functions/public/Merge-Toml.ps1; private helper src/functions/private/Merge-TomlTableObject.ps1.
Output type: [string] — canonical merged TOML text.
Implementation plan
Related
Scripts that work with layered configuration — defaults + environment overrides, base + local — need to merge TOML documents without writing ad-hoc hashtable loops.
Merge-Tomlcombines two or more TOML documents into one, mirroring the pattern ofMerge-Hashtablein the PSModule ecosystem.Request
Desired capability
Parameters
-BaseObject-OverrideObject-Path-LiteralPath-StrategyLastWins(default),FirstWins,ErrorOnConflictMerge semantics
-Strategy(default: last value wins)[[...]]): appended in order[string](canonical TOML)Acceptance criteria
Merge-Toml $a $bproduces TOML containing all keys from both; overlapping scalars obey-StrategyConvertFrom-Toml-ErrorOnConflictthrows on any duplicate scalar keyTechnical decisions
Implementation: Parse both inputs with
ConvertFrom-Toml, walk the resulting ordered dictionaries recursively with a private helperMerge-TomlTableObject, then re-serialize withConvertTo-Toml.Function placement:
src/functions/public/Merge-Toml.ps1; private helpersrc/functions/private/Merge-TomlTableObject.ps1.Output type:
[string]— canonical merged TOML text.Implementation plan
Merge-TomlTableObjectfor recursive merge logicMerge-Tomlinsrc/functions/public/Merge-Toml.ps1Related
ConvertFrom-Toml/ConvertTo-Toml(prerequisite)