title: jq: convert JSON file with arrays to CSV - transposed?
body: <p>I'm trying to use jq to convert a JSON output to CSV. </p>
  
  <p>Here's input.json (stripped down a lot - I may have up to 600 array elements, but the same number for each):</p>
  
  <pre><code>    {
    "latitude": [39.582, 39.582, 39.582],
    "longitude": [26.675, 26.675, 26.675],
    "drivingDifficultyIndex": [0, 34, 34],
    "iconCode": [31, 11, 11],
    "observationTimeUtcIso": ["2016-06-26T00:20:00+0000", "2016-06-26T01:20:00+0000", "2016-06-26T02:20:00+0000"],
    "precip1Hour": [0.0, 0.1, 0.5]
  }
  </code></pre>
  
  <p>My best attempt thus far is:</p>
  
  <pre><code>jq --raw-output 'keys , .[] | @csv'
  </code></pre>
  
  <p>which makes</p>
  
  <pre><code>"drivingDifficultyIndex","iconCode","latitude","longitude","observationTimeUtcIso","precip1Hour"
  39.582,39.582,39.582
  26.675,26.675,26.675
  0,34,34
  31,11,11
  "2016-06-26T00:20:00+0000","2016-06-26T01:20:00+0000","2016-06-26T02:20:00+0000"
  0,0.1,0.5
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/32960857/how-to-convert-arbirtrary-simple-json-to-csv-using-jq">How to convert arbirtrary simple JSON to CSV using jq?</a> gives some good hints, but I still end up with the data in rows (like above) rather than columns. </p>
  
  <p>What I'm after is this:</p>
  
  <pre><code>"latitude","longitude","drivingDifficultyIndex","iconCode","observationTimeUtcIso","precip1Hour"
  39.582, 26.675, 0,  31, \2016-06-26T00:20:00+0000\",    0
  39.582, 26.675, 34, 11, \"2016-06-26T01:20:00+0000\",   0.1
  39.582, 26.675, 34, 11, \"2016-06-26T02:20:00+0000\",   0.5
  </code></pre>
  
  <p>With up to 600 elements in each array, I need the CSV file to have a separate column for each array; rows 2 downwards need transposing.</p>
  
  <p>Can someone help jq produce the output I want?</p>
  
  <p>Thanks...</p>
  
  <p><strong>Update:</strong> </p>
  
  <pre><code>jq --raw-output 'keys_unsorted, map(.[0]) , map(.[1]), map(.[2]) |@csv'
  </code></pre>
  
  <p>gives me what I want, for the example 3 array members above. But how can I get this to work to account for much larger (unknown) number of array elements?</p>