Changes

Jump to navigation Jump to search
Add JSONL filtering example
Line 107: Line 107:  
If you don't have enough disk space to uncompress the .gz file, you can use zcat directly on the compressed file. Example:
 
If you don't have enough disk space to uncompress the .gz file, you can use zcat directly on the compressed file. Example:
 
  $ zcat openfoodfacts-products.jsonl.gz | jq -r '[.code,.product_name] | @csv' # output CSV data containing code,product_name
 
  $ zcat openfoodfacts-products.jsonl.gz | jq -r '[.code,.product_name] | @csv' # output CSV data containing code,product_name
 +
 +
==== Filtering JSONL export with jq ====
 +
Filtering a specific country:
 +
$ zcat openfoodfacts-products.jsonl.gz | jq '. | select(.countries_tags[]? == "en:germany")'
 +
 +
The previous command produces a json output containing all the products sold in Germany. If you want a JSONL output, add -c parameter.
 +
$ zcat openfoodfacts-products.jsonl.gz | jq -c '. | select(.countries_tags[]? == "en:germany")'
 +
 +
These operations can be quite long (more than 10 minutes depending on your computer and your selection).

Navigation menu