# Is there a cleaner way to use json\_query to filter an array based on the value of an attribute?

**URL:** <https://forum.ansible.com/t/is-there-a-cleaner-way-to-use-json-query-to-filter-an-array-based-on-the-value-of-an-attribute/25767>\
**Category:** Ansible Project\
**Created:** [October 18, 2017, 12:28am UTC](https://forum.ansible.com/t/is-there-a-cleaner-way-to-use-json-query-to-filter-an-array-based-on-the-value-of-an-attribute/25767 "2017-10-18T00:28:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Behrang](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Behrang](https://forum.ansible.com/u/Behrang)\
**Post date:** [October 18, 2017, 12:28am UTC](https://forum.ansible.com/t/is-there-a-cleaner-way-to-use-json-query-to-filter-an-array-based-on-the-value-of-an-attribute/25767/1 "2017-10-18T00:28:07Z")

</div>

Hi,

The version of Ansible we are using does not support selectattr to filter a list based on attribute names. So I instead use something like this:

```auto
set_fact:
  thing: '{{ (things | json_query("[?thing_name==''" + a_thing_name + "'']") | list)[0] }}'

```

Is there a cleaner way to do this? Without using double single-quotes for escaping and + for concatenation?
