나는 이것을 위해 jq 1.5를 사용하고 있습니다. 아래에 1.json과 2.json이라는 두 개의 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
여전히 운이 없다
이 특정 경우에는 다음 Statement
과 같이 두 개체의 필드를 간단히 추가 할 수 있습니다 .
jq '.Statement += input.Statement' file1 file2
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다