PowerShell module for reading and writing TOML data, with full TOML 1.0.0 specification support.
- PowerShell 7.6 LTS
- The PSModule framework for building, testing and publishing the module.
To install the module from the PowerShell Gallery, you can use the following command:
Install-PSResource -Name Toml
Import-Module -Name Toml$doc = ConvertFrom-Toml -InputObject @'
[database]
host = "localhost"
port = 5432
enabled = true
'@
$doc.Data.database.host # "localhost"
$doc.Data.database.port # 5432 [long]
$doc.Data.database.enabled # $true$doc = Import-Toml -Path './config.toml'
$doc.FilePath # absolute path to the file
$doc.Data # OrderedDictionary of all top-level keys$toml = ConvertTo-Toml -InputObject ([ordered]@{
title = 'My App'
version = 1
server = [ordered]@{
host = 'localhost'
port = 8080
}
})
# title = "My App"
# version = 1
#
# [server]
# host = "localhost"
# port = 8080$config = [ordered]@{
name = 'example'
enabled = $true
}
Export-Toml -InputObject $config -Path './output.toml'$doc = Import-Toml -Path './config.toml'
$doc.Data['version'] = 2
Export-Toml -InputObject $doc -Path './config.toml'Get-Content 'Cargo.toml' -Raw | Format-Toml
Format-Toml -Path 'Cargo.toml' -Indent 4Format-Toml parses then re-serializes TOML text, producing consistent key
quoting and canonical scalar forms — equivalent to
ConvertFrom-Toml | ConvertTo-Toml as a single call. TOML itself has no
indentation semantics; -Indent (default 2) only controls how many spaces
are used to visually nest table headers and their keys by depth. Set
-Indent 0 for the flat, unindented form.
$defaults = @'
[server]
host = "localhost"
port = 8080
'@
$overrides = @'
[server]
port = 9090
'@
Merge-Toml -BaseObject $defaults -OverrideObject $overrides
# [server]
# host = "localhost"
# port = 9090Merge-Toml also accepts -Path/-LiteralPath for merging files, and a -Strategy of LastWins (default), FirstWins, or ErrorOnConflict for resolving scalar key conflicts. Nested tables are always deep-merged and arrays of tables are always concatenated.
| TOML type | PowerShell type |
|---|---|
| String | [string] |
| Integer | [long] |
| Float | [double] |
| Boolean | [bool] |
| Offset date-time | [System.DateTimeOffset] |
| Local date-time | [System.DateTime] |
| Local date | [System.DateTime] |
| Local time | [System.TimeSpan] |
| Array | [object[]] |
| Table / Inline table | [ordered] hashtable |
| Array of tables | [object[]] of hashtables |
| Command | Description |
|---|---|
ConvertFrom-Toml |
Parse TOML text → TomlDocument |
ConvertTo-Toml |
Serialize object → TOML text |
Import-Toml |
Read TOML file → TomlDocument |
Export-Toml |
Write object or TomlDocument to file |
Format-Toml |
Normalize TOML text to canonical form |
Test-Toml |
Validate TOML text without throwing |
Merge-Toml |
Merge two TOML documents into one |
- Pure PowerShell parser and serializer — no external TOML runtime dependency.
- Duplicate keys and table redefinition are rejected per the TOML 1.0.0 spec.
- Files are written as UTF-8 without BOM.
See the examples folder for runnable scripts. Use PowerShell help for per-command examples:
Get-Help ConvertFrom-Toml -Examples
Get-Help Import-Toml -ExamplesFull documentation is available at psmodule.io/Toml.
Coder or not, you can contribute to the project! We welcome all contributions.
If you experience unexpected behavior, errors, or missing functionality, please open an issue on the issues tab.
Please read the Contribution guidelines and pick up an existing issue or submit a new one.