Changes

Jump to navigation Jump to search
Add an example when exporting a field containing array to CSV with jq
Line 133: Line 133:  
Filtering barcodes which are different from a code containing 1 to 13 digits:
 
Filtering barcodes which are different from a code containing 1 to 13 digits:
 
  $ zcat openfoodfacts-products.jsonl.gz | jq -r '. | select(.code|test("^[0-9]{1,13}$") | not) | .code' > ean_gt_13.csv
 
  $ zcat openfoodfacts-products.jsonl.gz | jq -r '. | select(.code|test("^[0-9]{1,13}$") | not) | .code' > ean_gt_13.csv
 +
Some part of the data are arrays, you must aggregate them using <code>join</code> for CSV export. For example, to export each product and its states in CSV:
 +
$ zcat openfoodfacts-products.jsonl.gz | jq -r '[.code,(.states_tags|join(","))] | @csv'
 
These operations can be quite long (more than 10 minutes depending on your computer and your selection).
 
These operations can be quite long (more than 10 minutes depending on your computer and your selection).
  

Navigation menu