Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 611

How to make a certain double cartesian product with jq?

$
0
0

Suppose I have this dataset:

{"id": 99, "labeled_values": [["one", "green"], ["two", "red"], ["three", "blue"]], "flavors": ["hot", "cold"]}{"id": 100, "labeled_values": [["four", "green"], ["five", "red"]], "flavors": ["hot"]}

and I would like this output (tab-separated):

99 one green hot99 two red hot99 one green cold99 two red cold100 four green hot100 five red hot

This code (from here) works without the flavors:

$ cat tmp/foo.ndjson | jq -r '[.id] + .labeled_values[] | @tsv'99  one green99  two red99  three   blue100 four    green100 five    red

Here is a failed attempt to add the flavor. It concatenates all the flavors, not one at a time.

$ cat tmp/foo.ndjson | jq -r '[.id] + .labeled_values[] + .flavors | @tsv'99  one green   hot cold99  two red hot cold99  three   blue    hot cold100 four    green   hot100 five    red hot

Viewing all articles
Browse latest Browse all 611

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>