title: ansible json-query path to select item by content
body: <p>Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below?  The JSON is a simplified stand-in for a massive and relatively complicated AWS blob.</p>
  
  <p>Some background: I was rather pleased to discover that Ansible has a json-query filter.  Given that I was trying to select an element from an AWS JSON blob this looked as if it was just what I needed.  However I quickly ran into trouble because the AWS objects have tags and I needed to select items by tag.  </p>
  
  <p>I tried selector paths equivalent to <code>Foods[Tags[(Key='For') &amp; (Value='Tigger')]]</code> and similar but didn't manage to get it to work.  Using a standalone json-query library such as <a href="https://www.npmjs.com/package/json-query" rel="nofollow noreferrer">https://www.npmjs.com/package/json-query</a> I can use the <code>parent</code> attribute but that does not appear to be in Ansible, quite apart from being a deviation from the core idea of json-query.</p>
  
  <p>It might be better to sidestep the problem and use a jsonpath selector.  jsonpath is similar to json-query and is a translation from xpath.</p>
  
  <pre><code>{ "Foods" :
    [ { "Id": 456
      , "Tags":
        [ {"Key":"For", "Value":"Heffalump"}
        , {"Key":"Purpose", "Value":"Food"}
        ]
      }
    , { "Id": 678
      , "Tags":
        [ {"Key":"For", "Value":"Tigger"}
        , {"Key":"Purpose", "Value":"Food"}
        ]
      }
    , { "Id": 911
      , "Tags":
        [ {"Key":"For", "Value":"Roo"}
        , {"Key":"Purpose", "Value":"Food"}
        ]
      }
    ]
  }
  </code></pre>
  
  <h3>References</h3>
  
  <ul>
  <li>json_query in ansible:
  <a href="http://docs.ansible.com/ansible/playbooks_filters.html#json-query-filter" rel="nofollow noreferrer">http://docs.ansible.com/ansible/playbooks_filters.html#json-query-filter</a></li>
  <li>json-query standalone node: <a href="https://www.npmjs.com/package/json-query" rel="nofollow noreferrer">https://www.npmjs.com/package/json-query</a></li>
  <li>jmespath, the library ansible uses: <a href="http://jmespath.org/" rel="nofollow noreferrer">http://jmespath.org/</a></li>
  <li>json-query standalone python: <a href="https://pypi.python.org/pypi/jsonquery/" rel="nofollow noreferrer">https://pypi.python.org/pypi/jsonquery/</a> (red herring)</li>
  </ul>