Using JQ how do I convert array of objects to key-value pair object?
Given the JSON:
[
{
"name": "foo",
"id": "123"
},
{
"name": "bar",
"id": "456"
}
]
Desired output:
{
"foo": "123",
"bar": "456"
}
Using JQ how do I convert array of objects to key-value pair object?
Given the JSON:
[
{
"name": "foo",
"id": "123"
},
{
"name": "bar",
"id": "456"
}
]
Desired output:
{
"foo": "123",
"bar": "456"
}
2
Answers
You can convert to an array of objects with
key
andvalue
keys, then usefrom_entries
:Here’s another way: