title: JSON to CSV: variable number of columns per row
body: <p>I need to convert JSON to CSV where JSON has arrays of variable length, for example:</p>
  
  <p>JSON objects:</p>
  
  <pre><code>{"labels": ["label1"]}
  {"labels": ["label2", "label3"]}
  {"labels": ["label1", "label4", "label5"]}
  </code></pre>
  
  <p>Resulting CSV:</p>
  
  <pre><code>labels,labels,labels
  "label1",,
  "label2","label3",
  "label1","label4","label5"
  </code></pre>
  
  <p>There are many other properties in the source JSON, this is just an exсerpt for the sake of simplicity.</p>
  
  <p>Also, I need to say that the process has to work with JSON as a stream because source JSON could be very large (>1GB).</p>
  
  <p>I wanted to use jq with two passes, the first pass would collect the maximum length of the 'labels' array, the second pass would create CSV as the number of the resulting columns is known by this time. But jq doesn't have a concept of global variables, so I don't know where I can store the running total.</p>
  
  <p>I'd like to be able to do that on Windows via CLI.
  Thank you in advance.</p>