I am making an API call to AWS and getting the output in the following format :
{
"ResourceTagMappingList": [
{
"ResourceARN": "<arn>",
"Tags": [
{
"Key": "CostCenter",
"Value": ""
},
{
"Key": "Region",
"Value": "us-west-2"
},
{
"Key": "Team",
"Value": "SRE"
}
]
{
"ResourceTagMappingList": [
{
"ResourceARN": "<arn>",
"Tags": [
{
"Key": "CostCenter",
"Value": "Development"
},
{
"Key": "Region",
"Value": "us-west-2"
},
{
"Key": "Team",
"Value": "Architects"
}
]
}, and so on
and i am trying to get the entire ResourceTagMappingList for when Costcenter is untagged. and i ran the jq query for this :
aws resourcegroupstaggingapi get-resources --tags-per-page 100 | jq '.ResourceTagMappingList[] | select(contains({Tags: [{Key: “CostCenter”} ]}) | not)'
But i keep running into the following :
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
.ResourceTagMappingList[] | select(contains({Tags: [{Key: “CostCenter”} ]}) | not)
jq: 1 compile error
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
[2] exit 120 aws resourcegroupstaggingapi get-resources --tags-per-page 100 --tag-filters |
exit 1 jq .ResourceTagMappingList[]
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
I’m not sure what i’m doing wrong here. any help will be appreciated. Thank you. I am on Mac and using CLI version aws-cli/2.13.25
>Solution :
jq and JSON only support the ASCII double quotes, not the "smart ones".
... | jq '.ResourceTagMappingList[] | select(contains({Tags: [{Key: “CostCenter”} ]}) | not)'
... | jq '.ResourceTagMappingList[] | select(contains({Tags: [{Key: "CostCenter"} ]}) | not)'
# ~ ~