我正在为此使用jq 1.5。我有两个json文件:下面的1.json和2.json。这两个文件都包含我想组合成一个文件(result.json)的Statement []对象数组。
1.json:
{
"Statement": [{
"Resource": [
"arn:aws:autoscaling:*:55555555:autoScalingGroup:*:autoScalingGroupName/${aws:PrincipalTag/Service}-*"
],
"Effect": "Allow",
"Action": [
"autoscaling:ExitStandby",
"autoscaling:RecordLifecycleActionHeartbeat"
],
"Sid": "ascIBP0"
}
],
"Version": "2012-10-17"
}
和2.json,其结构相同:Statement [...]
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:UpdateEventSourceMapping",
"lambda:CreateEventSourceMapping",
"lambda:DeleteEventSourceMapping"
],
"Effect": "Allow",
"Condition": {
"ArnLike": {
"lambda:FunctionArn": "arn:aws:lambda:*:*:function:${aws:PrincipalTag/Service}-*"
}
},
"Resource": "*",
"Sid": "lmbIBP0"
}
]
}
results.json
{
"Version": "2012-10-17",
"Statement": [
{
"Resource": [
"arn:aws:autoscaling:*:55555555:autoScalingGroup:*:autoScalingGroupName/${aws:PrincipalTag/Service}-*"
],
"Effect": "Allow",
"Action": [
"autoscaling:ExitStandby",
"autoscaling:RecordLifecycleActionHeartbeat"
],
"Sid": "ascIBP0"
},
{
"Action": [
"lambda:UpdateEventSourceMapping",
"lambda:CreateEventSourceMapping",
"lambda:DeleteEventSourceMapping"
],
"Effect": "Allow",
"Condition": {
"ArnLike": {
"lambda:FunctionArn": "arn:aws:lambda:*:*:function:${aws:PrincipalTag/Service}-*"
}
},
"Resource": "*",
"Sid": "lmbIBP0"
}
]
}
我已经接近了,但是我做错了。正在尝试这些组合:
jq -s '.[0] * .[1]' 1.json 2.json
jq -s '.[1] * .[0]' 1.json 2.json
jq -s '.[] * .[]' 1.json 2.json
仍然没有运气
答案 0 :(得分:1)
对于这种特定情况,您可以简单地添加两个对象的Statement
字段,如下所示:
jq '.Statement += input.Statement' file1 file2