Open indolering opened 7 years ago
@indolering jq is a lightweight and flexible command-line JSON processor.jq does not support processing csv data now.
@Alanscut - Although it is true that jq has no built-in filter for parsing non-trivial CSV, jq is Turing-complete and in fact it's not difficult to write a PEG parser for CSV. The reason this is not commonly done is probably that in practice, it's more convenient to use a CSV-to-TSV converter in conjunction with jq since jq handles TSV well.
For an example of using jq to handle a large, "real-world" CSV file, see https://infiniteundo.com/post/99336704013/convert-csv-to-json-with-jq.
For an excellent implementation of an rfc4180 parser in jq, see "def fromcsv:" by fadado at https://github.com/stedolan/jq/issues/1650 (Dec 22, 2018)
For PEG parsing with jq in general, see https://github.com/stedolan/jq/wiki/Parsing-Expression-Grammars
For a PEG-based CSV parser written in jq, see my own https://gist.github.com/pkoppstein/bbbbdf7489c8c515680beb1c75fa59f2
Sure, you can output CSV and TXT ... but can you convert CSV to JSON or TXT into an array?