I need to convert JSON to CSV where JSON has arrays of variable length, for example:

JSON objects:

```
{"labels": ["label1"]}
{"labels": ["label2", "label3"]}
{"labels": ["label1", "label4", "label5"]}

```

Resulting CSV:

```
labels,labels,labels
"label1",,
"label2","label3",
"label1","label4","label5"

```

There are many other properties in the source JSON, this is just an exсerpt for the sake of simplicity.

Also, I need to say that the process has to work with JSON as a stream because source JSON could be very large (>1GB).

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.

I'd like to be able to do that on Windows via CLI.
Thank you in advance.