951
edits
(Add JSONL filtering example) |
(Multiple filter and CSV export) |
||
Line 114: | Line 114: | ||
The previous command produces a json output containing all the products sold in Germany. If you want a JSONL output, add -c parameter. | 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")' | $ zcat openfoodfacts-products.jsonl.gz | jq -c '. | select(.countries_tags[]? == "en:germany")' | ||
You can add multiple filters and export the result to a CSV file. For example, here is a command that 1. selects products having the Nutri-Score computed and belonging to the TOP 90% most scanned products in 2020, and 2. exports barcode (<code>code</code>) and number of scans (<code>scans_n</code>) as a CSV file. | |||
$ zcat openfoodfacts-products.jsonl.gz | jq -r '. | select(.misc_tags[]? == "en:nutriscore-computed" and .popularity_tags[]? == "top-90-percent-scans-2020") | [.code,.scans_n] | @csv' > displayed.ns.in.top90.2020.world.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). |