Answers: <p>Take heart, I've been struggling with JMESPath query expressions for the past couple of years!  It's been a long time getting used to them.</p>
  <p>In your example output, <code>Tags</code> is a JSON object rather than a list, so the <code>[]</code> in your JMESPath expression is causing the error.  Try this as your <code>jq</code> command:</p>
  <pre><code>jq '.Tags.Name'
  </code></pre>
  <p>You'll get:</p>
  <pre><code>&quot;bar-queue&quot;
  </code></pre>
  <p>You can use the <code>-r</code> option to <code>jq</code> to get the output without quotes.</p>
  <p>However I think you can do better by having the <code>aws</code> command do this filtering for you.  Try the <code>--query</code> option:</p>
  <pre><code>aws sqs list-queue-tags --region sa-east-1 --queue-url &lt;my-url-queue&gt; --query 'Tags.Name'
  </code></pre>
  <p>Yes, the expression for the <code>aws</code> command doesn't have the leading <code>.</code>.  If you don't want the quotes around the output, add the option <code>--output text</code>.</p>
  <hr />
  <p><em>Edited to add these notes about JMESPath expressions for jq vs. aws:</em></p>
  <p>The leading <code>.</code> character isn't the only difference between expressions that <code>jq</code> likes and the ones the <code>aws</code> command likes.  I don't have an exhaustive list, but I have needed to use different quotes around path names for one program than I used for the other.</p>
  <p>There are pretty good tutorials on query expressions for each of these programs:</p>
  <ul>
  <li><strong>jq</strong> : <a href="https://stedolan.github.io/jq/tutorial/" rel="nofollow noreferrer">https://stedolan.github.io/jq/tutorial/</a></li>
  <li><strong>aws</strong> : <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html</a></li>
  </ul>
  <p>And a website that's useful for interactively trying out expressions, once you've figured out how the site works:  <a href="https://jmespath.org" rel="nofollow noreferrer">https://jmespath.org</a> .  It includes a link to another, more general tutorial.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-07-14T14:56:45.837Z
Answers: Great bro, thanks for the explanation, both examples works fine!
Answers: Vader
Answers: CC BY-SA 4.0
Answers: 2022-07-14T07:10:45.537Z
Answers: 2022-07-20T16:48:27.537Z
Answers: 2022-07-20T16:48:27.537Z
Answers: Sotto Voce
Body: <p>I'm having doubts when trying to run a query with JQ.
  I have an SQS queue with Tags applied and when I run</p>
  <p><code>aws sqs list-queue-tags --region sa-east-1 --queue-url &lt;my-url-queue&gt; --output json | jq</code></p>
  <p>returns the output:</p>
  <pre><code>{
    &quot;Tags&quot;: {
      &quot;owner&quot;: &quot;foo&quot;,
      &quot;Name&quot;: &quot;bar-queue&quot;
    }
  }
  </code></pre>
  <p>So...I just filter using like this:</p>
  <p><code>aws sqs list-queue-tags --region sa-east-1 --queue-url &lt;my-url-queue&gt; --output json | jq '.Tags[] | [.Name]'</code></p>
  <p>or</p>
  <p><code>aws sqs list-queue-tags --region sa-east-1 --queue-url &lt;my-url-queue&gt; --output json | jq '.Tags[].Name'</code></p>
  <p>and other methods without success, always output: <code>jq: error (at &lt;stdin&gt;:6): Cannot index string with string &quot;Name&quot; </code></p>
  <p>Maybe I'm having a noobie hahaha, but someone can help me?</p>
  
Tags: <aws-cli><amazon-sqs>
Title: Filtering AWS SQS Tags using JQ
UserDisplayName: Vader
ThreadText: # Filtering AWS SQS Tags using JQ
  
  (Asked by: username_0 on 2022-07-13)
  
  I'm having doubts when trying to run a query with JQ.
  I have an SQS queue with Tags applied and when I run
  
  `aws sqs list-queue-tags --region sa-east-1 --queue-url <my-url-queue> --output json | jq`
  
  returns the output:
  
  ```
  {
    "Tags": {
      "owner": "foo",
      "Name": "bar-queue"
    }
  }
  
  ```
  
  So...I just filter using like this:
  
  `aws sqs list-queue-tags --region sa-east-1 --queue-url <my-url-queue> --output json | jq '.Tags[] | [.Name]'`
  
  or
  
  `aws sqs list-queue-tags --region sa-east-1 --queue-url <my-url-queue> --output json | jq '.Tags[].Name'`
  
  and other methods without success, always output: `jq: error (at <stdin>:6): Cannot index string with string "Name"`
  
  Maybe I'm having a noobie hahaha, but someone can help me?
  
  **Tags:** aws-cli, amazon-sqs
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-14. Score: 1 | Accepted answer
  
  Take heart, I've been struggling with JMESPath query expressions for the past couple of years! It's been a long time getting used to them.
  
  In your example output, `Tags` is a JSON object rather than a list, so the `[]` in your JMESPath expression is causing the error. Try this as your `jq` command:
  
  ```
  jq '.Tags.Name'
  
  ```
  
  You'll get:
  
  ```
  "bar-queue"
  
  ```
  
  You can use the `-r` option to `jq` to get the output without quotes.
  
  However I think you can do better by having the `aws` command do this filtering for you. Try the `--query` option:
  
  ```
  aws sqs list-queue-tags --region sa-east-1 --queue-url <my-url-queue> --query 'Tags.Name'
  
  ```
  
  Yes, the expression for the `aws` command doesn't have the leading `.`. If you don't want the quotes around the output, add the option `--output text`.
  
  ---
  
  *Edited to add these notes about JMESPath expressions for jq vs. aws:*
  
  The leading `.` character isn't the only difference between expressions that `jq` likes and the ones the `aws` command likes. I don't have an exhaustive list, but I have needed to use different quotes around path names for one program than I used for the other.
  
  There are pretty good tutorials on query expressions for each of these programs:
  
  * **jq** : <https://stedolan.github.io/jq/tutorial/>
  * **aws** : <https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html>
  
  And a website that's useful for interactively trying out expressions, once you've figured out how the site works: <https://jmespath.org> . It includes a link to another, more general tutorial.
  
  > **Comments:**
  > **username_0**: Great bro, thanks for the explanation, both examples works fine!  
  
  ---
  
  