如果我有一个这样的数组:
[
[
"AppA",
"ServiceA",
"SecretKey",
"topSecretKeyA"
],
[
"AppB",
"ServiceB",
"SecretKey",
"topSecretKeyB"
],
[
"AppC",
"ServiceC",
"SecretKey",
"topSecretKeyC"
]
]
如何将其转换为如下所示的对象?
{
"AppA": {
"ServiceA": {
"SecretKey": "topSecretKeyA"
}
},
"AppB": {
"ServiceB": {
"SecretKey": "topSecretKeyB"
}
},
"AppC": {
"ServiceC": {
"SecretKey": "topSecretKeyC"
}
}
}
我想我需要使用reduce,但我不太清楚该怎么做。我已经尝试了一些变化:jq 'reduce .[] as $k (null; {($k: .})'
2条答案
按热度按时间m1m5dgzv1#
使用
setpath
(手动)将给定路径设置为一个值:gj3fmq9x2#
使用
map
和from_entries