The syntax [...]*N only works for strings and does not work for lists. Also, I haven't found a built-in in the manual that does this task easily.
So I had to do something like
[range(N)|...]|add
Is there an easier (or more idiomatic) way to replicate a list in jq N times?
The syntax you're looking for does not exist. Your best bet would be to define a function to repeat the value for a reusable option.
def repeat($n):
. as $val | range($n) | $val;
In your case, to create an array which repeats the contents of another array N times, you could use the above to do this:
[repeat($N)[]]
for some number $N.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With