zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.71k stars 365 forks source link

If no field list, use all fields from first record #321

Closed johnyesberg closed 6 years ago

johnyesberg commented 6 years ago

Hi and thanks again.

My JSON records are very large and all have identical structure. Writing out the field list is tedious. I think that a principle-of-least-surprise option might be that if there is no list of fields specified, then json2csv uses all of the fields from the first record. I'd be interested in your thoughts.

Best wishes John

juanjoDiaz commented 6 years ago

Hi @johnyesberg,

That's pretty much how it works. The stream API (which is the one intended for large datasets) does exactly that. The sync API (which is intended for small dataset) goes through all the records in the dataset and collect all the possible fields before actually doing the conversion to CSV.

knownasilya commented 6 years ago

The above works as long as you haven't specified your own fields.