Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)'
#                                                                   ~          ~
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading