Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

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

$
0
0

Given a json file in the format as :

[ {  name : "A",  value : "1" }, {  name : "B",  value : "5" }, {  name : "E",  value : "8" }]

How would I convert it to something like this using jq:

{"A" : {   name : "A",   value : "1" },"B" : {  name : "B",  value : "5" },"E" : {  name : "E",  value : "8" }}

jq '{(.[].name) : "the name"}''myfile.json' gets me an object with [].name keys but how do I assign the object to it?


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>