JQ error when trying to parse JSON string - unexpected '['

46 Views Asked by At

When trying to query a JSON str, using the script below, I get an error.

db_secret_data=$(aws secretsmanager get-secret-value --secret-id "$db_secret_name" --output json)
    
echo "$db_secret_data"
 
db_secret_str=$(echo "$db_secret_data" | jq --arg keyvar "${uid_str}-TY" '.SecretString.[$keyvar]' -r)

Here is the error:

jq: error: syntax error, unexpected '[', expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at <top-level>, line 1:
.SecretString.[$keyvar]   

I've gone over the syntax over and over, and can't see what's wrong. Can anyone help?

1

There are 1 best solutions below

3
choroba On BEST ANSWER

Remove the dot before the key:

.SecretString[$keyvar]
            ~~