[jq] Swap the rows and columns of a nested array

Created on November 30, 2026

Use transpose to turn columns into rows. Here each input row contains a name and score. The output groups the names and the scores separately.

printf '%s\n' '[["Taro",80],["Hanako",95]]' | jq 'transpose'
[
  [
    "Taro",
    "Hanako"
  ],
  [
    80,
    95
  ]
]

When the input rows differ in length, jq fills missing entries with null.

printf '%s\n' '[[1,2],[3]]' | jq 'transpose'
[
  [
    1,
    3
  ],
  [
    2,
    null
  ]
]

The second input row lacks a second column, so the second output row ends in null.

Reference

jq