#2853·yq

TOML parsing & conversion does not preserve object order

Author: 5HT2Created Sep 2, 2026Updated Sep 2, 2026
Labelsbugv4

Describe the bug A clear and concise description of what the bug is.

Note that any how to questions should be posted in the discussion board and not raised as an issue.

Version of yq: yq (https://github.com/mikefarah/yq/) version v4.53.6 Operating system: macOS 14.7.6 Installed via: binary, homebrew

Input Yaml Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less) data1.toml:

toml
[dependencies]
crossterm = { version = "0.29.0", features = ["serde"] }
dirs = "6"
libc = "0.2.*"

[target."cfg(not(all(windows, target_arch = \"x86\", target_env = \"gnu\")))".dependencies]
# if ssl feature is enabled compilation will fail on arm-unknown-linux-gnueabihf and i686-pc-windows-gnu
git2 = { version = "0.20", optional = true, default-features = false }

[target.'cfg(unix)'.dependencies]
users = { version = "0.12", package = "uzers" }
xattr = "1"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.61.3", features = ["Win32_Foundation", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Memory"] }

[dependencies.clap]
features = ["derive", "wrap_help"]
version = "4.5.*"

data2.toml:

toml
[dependencies]
crossterm = { version = "0.29.0", features = ["serde"] }
dirs = "6"
libc = "0.2.*"

[dependencies.clap]
features = ["derive", "wrap_help"]
version = "4.5.*"

[target."cfg(not(all(windows, target_arch = \"x86\", target_env = \"gnu\")))".dependencies]
git2 = { version = "0.20", optional = true, default-features = false }
[target."cfg(unix)".dependencies]
users = { version = "0.12", package = "uzers" }
xattr = "1"

[target."cfg(windows)".dependencies]
windows = { version = "0.61.3", features = ["Win32_Foundation", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Memory"] }

Command The command you ran:

bash
<data1.toml yq -ptoml -otoml

Actual behaviour

diff
--- /dev/fd/11	2026-09-02 20:47:02
+++ /dev/fd/14	2026-09-02 20:47:02
@@ -3,17 +3,15 @@
 dirs = "6"
 libc = "0.2.*"
 
+[dependencies.clap]
+features = ["derive", "wrap_help"]
+version = "4.5.*"
+
 [target."cfg(not(all(windows, target_arch = \"x86\", target_env = \"gnu\")))".dependencies]
-# if ssl feature is enabled compilation will fail on arm-unknown-linux-gnueabihf and i686-pc-windows-gnu
 git2 = { version = "0.20", optional = true, default-features = false }
-
-[target.'cfg(unix)'.dependencies]
+[target."cfg(unix)".dependencies]
 users = { version = "0.12", package = "uzers" }
 xattr = "1"
 
-[target.'cfg(windows)'.dependencies]
+[target."cfg(windows)".dependencies]
 windows = { version = "0.61.3", features = ["Win32_Foundation", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Memory"] }
-
-[dependencies.clap]
-features = ["derive", "wrap_help"]
-version = "4.5.*"

Expected behaviour

Ordering should have been retained.

Additional context

See #170, #435, #274, #559