wireservice / csvkit

A suite of utilities for converting to and working with CSV, the king of tabular file formats.
https://csvkit.readthedocs.io
MIT License
6.03k stars 603 forks source link

in2csv fields order output (bis) #1165

Closed JPlanche closed 2 years ago

JPlanche commented 2 years ago

Hello.

Thank your for this wonderful program.

For this attached JSON file, if I do: in2csv -f ndjson output.txt > output.csv

The column order is strange. The "cflag/0" column is between the "poisson" columns.

Verbose flag displays nothing.

$ in2csv --version
in2csv 1.0.5

$ python --version
Python 2.7.18

$ python3 --version
Python 3.9.10

MacOS 12.2.1

output.txt output.csv

jpmckinney commented 2 years ago

The fields are ordered as they are "seen". The first two rows of JSON have a null cflag and two-value arrays in poisson. The third row has a single-value array in cflag (which csvkit sees first) and then a three-value array in poisson.

You can imagine the sorting logic would get pretty complicated if a later cflag instead contains an object containing an array like "cflag": {"foo": ["bar", "baz"]}.

So, this is wontfix.