Using jq, convert array of objects to object with named keys

一个人想着一个人 提交于 2019-11-30 17:41:32
map( { (.name|tostring): . } ) | add

(The tostring is for safety/robustness.)

INDEX/1

If your jq has INDEX/1 (introduced after the release of version 1.5), you can simply write:

INDEX(.name)

Just build up a new object going through the items in the array. Add the items to the object with the name as the key.

reduce .[] as $i ({}; .[$i.name] = $i)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!