I have created a csv output from an input JSON file.
Since some JSON arrays do not have their own id's, I need to add a unique id in my csv output that will be based on index of current element in its JSON array.
Is there any built-in JQ function returning the element index?
to_entries
should work perfectly.
jq -n '["a","b","c"] | to_entries'
will produce
[{"key":0,"value":"a"},{"key":1,"value":"b"},{"key":2,"value":"c"}]
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