Skip to content

yq TOML output prioritizes compact hash table syntax over readability #2632

@danielb2

Description

@danielb2

v4.52.4

Please describe your feature request.
I wish yq would prefer readable TOML tables instead of collapsing structures into the { ... } hash table form when emitting TOML.

TOML exists primarily for human readable configuration. The spec describes TOML as:

"A config file format for humans. TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics."

When yq converts data and emits TOML, it sometimes collapses structures into the compact hash table form. While valid TOML, this makes configuration files harder to read and scan. The hierarchy becomes compressed into a single line.

For example, if we have data.toml:

[arg]
hello = "foo"

and run:

yq data.toml -oy | yq -o toml

the output becomes:

arg = { hello = "foo" }

This is technically correct TOML, but it works against the main reason people choose TOML for configuration, readability.

Most TOML in the ecosystem uses section headers because they make structure obvious and diffs easier to read.

Describe the solution you'd like

Prefer emitting standard TOML tables when serializing structures.

For example, given:

arg:
  hello: foo

Running:

yq -o toml

should output:

[arg]
hello = "foo"

instead of collapsing the structure into the compact hash table form.

Describe alternatives you've considered

Currently the only way to reliably keep readable TOML output is to avoid certain transformations or avoid round tripping through YAML.

For example:

yq data.toml -otoml

preserves the table structure, but a YAML round trip:

yq data.toml -oy | yq -o toml

does not.

Another option would be a flag to control this behavior, but preferring readable tables by default would better match TOML’s goal as a human focused configuration format.

Additional context

TOML was explicitly designed for human readable configuration files. Collapsing structures into { ... } hash tables reduces the visual structure that table headers provide and makes large configs harder to review and maintain.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions