If I have an array such as this one:
[
[
"AppA",
"ServiceA",
"SecretKey",
"topSecretKeyA"
],
[
"AppB",
"ServiceB",
"SecretKey",
"topSecretKeyB"
],
[
"AppC",
"ServiceC",
"SecretKey",
"topSecretKeyC"
]
]
How can I convert this to an object that looks like the following?
{
"AppA": {
"ServiceA": {
"SecretKey": "topSecretKeyA"
}
},
"AppB": {
"ServiceB": {
"SecretKey": "topSecretKeyB"
}
},
"AppC": {
"ServiceC": {
"SecretKey": "topSecretKeyC"
}
}
}
I think I need to use reduce but I can’t quite figure out how to do it. I have tried a number of variations of this:
jq 'reduce .[] as $k (null; {($k: .})'
2
Answers
Use
setpath
(manual) to set a given path to a value:with
map
andfrom_entries