JQ 将数组映射到具有索引的对象 - 如何

JQ to map array to object with index - how to

很简单:

我有:'["a","b","c"]'

我想要的:

{
  "1":"a",
  "2":"b",
  "3":"c"
}

我在做什么。

echo '["a","b","c"]' | jq '. | map({(index(.)) : (.)})'

我得到了什么(它似乎在连续较小的数组上运行):

 echo '["a","b","c"]' | jq '. | map(index((.)))'
[
  0,
  0,
  0
]

功能性解决方案:

[to_entries[] | {(.key+1|tostring): .value}] | add

或者,更简洁:

with_entries(.key |= (1+.|tostring))

或者,更通俗地说:

. as $in
| reduce range(0;length) as $i (null; 
    . + {($i+1|tostring): $in[$i]})