Hacker News new | ask | show | jobs
by micimize 1521 days 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.
1 comments

Your `.name as $name` was my immediate attempt too, but it turns out you can go even simpler with

  jq '{name, val: .vals[]}'