| "cobbled-together" jq as it often appears in the wild will
often compare badly with crafted solutions because the writer's
goal is usually GSD and not write pretty code. People with the time and inclination to slow down and think a
little more about how the tools work will produce cleaner solutions. In your example to convert {"name":"foo","vals":[1,2,3]}
to {"name":"foo","val":1}
{"name":"foo","val":2}
{"name":"foo","val":3}
All you need is this jq filter {name:.name, val:.vals[]}
To me this is much better than the proposed zq or jq solution you're using as a basis
for comparison. You could almost use the shorter .vals = .vals[]
if the name in the output didn't change.These filters takes advantage of how jq's [] operator converts a single
result into separate results. For people new to jq this behavior is often
confusing unless they've seen things like Cartesian products. .[] - https://stedolan.github.io/jq/manual/#Array/ObjectValueItera... |