4 ms·
Their syntax comparison under "So you like chocolate or vanilla?" is disingenuous. You can do variable assignment and array expansion in jq: expand_vals_into
by micimize 4y ago
Their syntax comparison under "So you like chocolate or vanilla?" is disingenuous. You can do variable assignment and array expansion in jq:
expand_vals_into_independent_records='
.name as $name | .vals[] | { name: $name, val: . }
'
echo '{"name":"foo","vals":[1,2,3]} {"name":"bar","vals":[4,5]}' |
jq "$expand_vals_into_independent_records"
Also, generally, not a fan of the tone of this article.
- lilyball 4y agoYour `.name as $name` was my immediate attempt too, but it turns out you can go even simpler with jq '{name, val: .vals[]}'