Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Reusing Open Food Facts Data
(view source)
Revision as of 16:39, 5 October 2022
247 bytes added
,
16:39, 5 October 2022
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).
Charlesnepote
Bureaucrats
,
Administrators
984
edits
Navigation menu
Personal tools
English
Log in
Namespaces
Page
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Log in
Open Food Facts galaxy
📍Where am I?
🍊Open Food Facts website
Open Food Facts wiki
Main page
Recent changes
Random page
🧴 Open Beauty Facts wiki
Main page
Deep dive per topic
All topics
Whole wiki
Help about MediaWiki
Icons in the wiki
Tools
Special pages
Printable version
Admins
Edit sidebar
Styling
Replace text
Special Pages