// converters
YAML to TOML.
Translate a YAML map (flat or with arrays) into TOML keys with safe string quoting.
YAML input
TOML output
YAML to TOML — when and why.
TOML is preferred in ecosystems where strict typing and unambiguous parsing matter: Rust (Cargo.toml), Python (pyproject.toml), and many CLI tools. If you have a YAML config and need to provide it to a tool that expects TOML, this converter handles the transformation.
TOML's advantage over YAML is predictability: yes is always a string in TOML, but in YAML it's a boolean. 0123 is an error in TOML (leading zeros not allowed) but a string in YAML. Convert to TOML when you need this strictness.
Conversion limits.
YAML is more expressive than TOML in some areas. Anchors and aliases (&default / *default) have no TOML equivalent and are dropped. Mixed-type arrays (e.g., [1, "two", true]) are invalid in TOML. Complex keys (keys containing special characters or multi-line strings) may need quoting in TOML.
The converter handles common cases well: nested objects, arrays of primitives, typed values, and multi-document YAML. If your YAML uses advanced features like merge keys (<<:) or custom tags (!!python/object), the converter will flag the unsupported feature.
TOML structure.
TOML uses sections for nesting: [database] starts a section, and database.host = "db.internal" adds a key inside it. Nested sections use double brackets: [database.primary]. Inline tables ({ host = "db.internal", port = 5432 }) are equivalent but more compact. The converter chooses the most readable format for each level of nesting.
Common conversion scenarios.
Docker Compose to Podman. Podman supports TOML-based configuration for some settings. Convert your docker-compose.yml environment variables or volume definitions to TOML when migrating to Podman's rootless container runtime.
CI/CD pipelines. Many CI systems (GitHub Actions, GitLab CI) use YAML, but tool-specific configs like Cargo, pip, or Poetry expect TOML. Convert shared configuration blocks to TOML so a single source of truth can feed both the pipeline and the package manager.
Infrastructure as code. Terraform and Packer configurations increasingly favour TOML for variable files and plugin definitions. Convert existing YAML variable sets to TOML to keep your infrastructure code consistent across tools. The conversion preserves all data types and nesting, making it easy to maintain configuration across different ecosystems.
How the converter handles types.
YAML infers types implicitly — 42 is an integer, true is a boolean, "hello" is a string. TOML requires explicit typing in some contexts. The converter preserves inferred types where possible and adds quotes around strings that could be mistaken for other types. For example, YAML's yes (a boolean) becomes TOML's true, while a quoted "yes" stays as a string.
Date and time values are converted to TOML's native datetime format when they match ISO 8601 patterns. Null values in YAML become empty strings or are omitted, since TOML has no null type. These type conversions happen automatically — you don't need to annotate your YAML with explicit types for the converter to work correctly. The output is valid TOML that can be used directly in Cargo.toml, pyproject.toml, or any other TOML-based configuration file. This makes it easy to migrate configuration between ecosystems without manual reformatting.
FAQ
How do I convert a YAML config to TOML in Python?
Load YAML with `yaml.safe_load`, then use `tomli_w.dump(data, f)` or `tomlkit.dump(doc, f)` to write TOML — note that TOML requires explicit table headers for nested data.
Why does my YAML-to-TOML conversion lose nested structure?
TOML uses explicit `[table.subtable]` headers vs YAML's indentation — most converters flatten and reconstruct; use `tomlkit` for round-trip-safe conversion that preserves comments.
Can I convert YAML arrays to TOML arrays of tables?
Yes — `{items: [{name: a}, {name: b}]}` becomes `[[items]]\nname = "a"\n[[items]]\nname = "b"`; converters like `tomlkit` and `yaml2toml` handle this.
How do I preserve YAML comments when converting to TOML?
Use `ruamel.yaml` (round-trip YAML) + `tomlkit` (preserves TOML comments); standard PyYAML drops comments on parse, so they're lost in conversion.
Is there a CLI tool for YAML-to-TOML conversion?
`yaml2toml` (Python pip install) and `taplo` (Rust CLI for TOML) can convert; or use `yq -o=toml` if your `yq` version supports TOML output.