TOML encoder: prefer readable table sections over inline tables#2649
Draft
TOML encoder: prefer readable table sections over inline tables#2649
Conversation
When converting from YAML/JSON to TOML, the encoder now always uses
readable TOML table section syntax ([section]) instead of compact inline
hash table syntax (key = { ... }), which better matches TOML's goal as
a human-focused configuration format.
Changes:
- decoder_toml.go: Mark inline TOML tables with FlowStyle so round-trips
can be distinguished from YAML flow mappings
- encoder_toml.go:
- encodeTopLevelEntry: use FlowStyle check instead of EncodeSeparate to
decide inline vs table section (all block mappings now become tables)
- encodeSeparateMapping: count FlowStyle children as attributes; use
recursive encodeSeparateMapping for nested non-flow mappings
- encodeMappingBodyWithPath: emit non-flow child mappings as sub-table
sections instead of inline tables
- toml_test.go: add encode (YAML→TOML) test scenarios, update roundtrip
expectations for inline tables (now expanded to table sections)
Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/4824a219-6d5e-42e7-bca1-a8a277bf8c6a
Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for readable TOML output in yq
TOML encoder: prefer readable table sections over inline tables
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When encoding to TOML from YAML/JSON, nested mappings were collapsed into compact inline table syntax (
key = { ... }) instead of idiomatic TOML table sections ([key]). This affected both direct YAML→TOML conversion and round-trips through YAML.Changes
Encoder (
encoder_toml.go)encodeTopLevelEntry: ReplaceEncodeSeparatecheck withFlowStylecheck — only nodes explicitly marked as flow/inline stay inline; all block mappings become table sectionsencodeSeparateMapping: CountFlowStylemapping children ashasAttrs(they render askey = { ... }); replacewriteTableHeader + encodeMappingBodyWithPathwith recursiveencodeSeparateMappingin the "no attrs" loopencodeMappingBodyWithPath: Emit non-flow child mappings as sub-table sections ([parent.child]) instead of inline tablesDecoder (
decoder_toml.go)Style: FlowStyleon decoded inline TOML tables, distinguishing them from block mappings so they survive re-encoding as inlineTests (
toml_test.go)encodescenario type (YAML→TOML) and coverage for table section outputBefore / After
YAML flow mappings (
arg: {hello: foo}) are preserved as TOML inline tables, respecting the author's explicit style intent.