【发布时间】:2021-04-01 15:37:52
【问题描述】:
我正在尝试合并以下两个 json 文件;但我似乎只能部分合并;一旦元素在数组中,reduce 就会失败。
{
"value1": 200,
"timestamp": 1382461861,
"deployment": [
{
"component": "whatever",
"containers": "key value"
}
]
}
和
{
"status": 200,
"timestamp": 1382461861,
"deployment": [
{
"autoscaling": {
"maxReplicas": 1,
"minReplicas": 1,
"targetCPUUtilizationPercentage": 40
}
}
]
}
如果输入是数组,则使用jq -s 'reduce .[] as $item({}; . * $item)' x.json x2.json 不起作用;相反,我得到了部分合并,但没有得到深度合并
{
"value1": 200,
"timestamp": 1382461861,
"deployment": [
{
"autoscaling": {
"maxReplicas": 1,
"minReplicas": 1,
"targetCPUUtilizationPercentage": 40
}
}
],
"status": 200
}
预期的输出是
{
"value1": 200,
"timestamp": 1382461861,
"deployment": [
{
"component": "whatever",
"containers": "key value",
"autoscaling": {
"maxReplicas": 1,
"minReplicas": 1,
"targetCPUUtilizationPercentage": 40
}
}
],
"status": 200,
}
谁能告诉我哪里出错了
【问题讨论】:
标签: json object merge jq array-merge