# Is there a cleaner alternative to '{{ (things | json\_query("\[?name==''" + thing\_name + "''\]")  }}'

**URL:** <https://forum.ansible.com/t/is-there-a-cleaner-alternative-to-things-json-query-name-thing-name/25859>\
**Category:** Ansible Project\
**Created:** [October 30, 2017, 12:55am UTC](https://forum.ansible.com/t/is-there-a-cleaner-alternative-to-things-json-query-name-thing-name/25859 "2017-10-30T00:55:31Z")\
**Posts on this page:** 3\
**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 30, 2017, 12:55am UTC](https://forum.ansible.com/t/is-there-a-cleaner-alternative-to-things-json-query-name-thing-name/25859/1 "2017-10-30T00:55:31Z")

</div>

Is there a cleaner alternative to:

‘{{ (things | json\_query("[?name==’‘" + thing\_name + "’‘]") }}’

In particular, ideally I want to avoid:

- String concatenation

- Escaping of quotes

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [October 30, 2017, 2:00am UTC](https://forum.ansible.com/t/is-there-a-cleaner-alternative-to-things-json-query-name-thing-name/25859/2 "2017-10-30T02:00:22Z")

</div>

You can move the actual query string to a separate variable to reduce some clutter and string concatenation. You can also use ` (backticks) to quote jmes\_path strings:

set\_fact:  
enabled\_ports: “{{ intfs | json\_query(enabled)}}”  
vars:  
enabled: “values(@)[?is\_enabled && is\_up && vlan\_tag == `{{ mgmt_vlan }}`]”

kind regards  
Pshem

---

<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 30, 2017, 11:16am UTC](https://forum.ansible.com/t/is-there-a-cleaner-alternative-to-things-json-query-name-thing-name/25859/3 "2017-10-30T11:16:32Z")

</div>

Perfect! Thanks.
