test.json
{
"Version": "2012-**-**",
"Statement": [
{ "Effect": "**",
"Principal": "**",
"Action": "**",
"Resource": "***",
"Condition": {
"IpAddress": {
"aws:SourceIp": [ "127.0.0.1", "1.0.0.2" ]
}
}
}
]
}
I would like to pop the array of aws:SourceIp so that the 1.0.0.2, or whatever the last element of the array is removed. The return value should be the whole json object with the array missing the 1.0.0.2.
I have come close with this:
echo $(jq '.Statement[0] .Condition.IpAddress."aws:SourceIp" | .[0:-1] ' test.json ) > test.json
With the help of: https://github.com/stedolan/jq/issues/226
This will pop the last element of the array but return only [ "127.0.0.1"] and then push this in to test.json.
I would like it to return the whole json modified so that I can then be pushed in to test.JSON