# Using json query filter

**URL:** <https://forum.ansible.com/t/using-json-query-filter/24860>\
**Category:** Ansible Project\
**Created:** [June 30, 2017, 10:47am UTC](https://forum.ansible.com/t/using-json-query-filter/24860 "2017-06-30T10:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trg.achilles](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@trg.achilles](https://forum.ansible.com/u/trg.achilles)\
**Post date:** [June 30, 2017, 10:47am UTC](https://forum.ansible.com/t/using-json-query-filter/24860/1 "2017-06-30T10:47:43Z")

</div>

Hello,

I’m trying to determined if package is installed and what version  
I have the following tasks

vars:  
cmk\_version: 1.4.0p7

- name: Check if check-mk-raw package is installed  
yum:  
list: installed  
register: yum\_packages

- name: Display cmk\_installed\_version  
debug:  
var: item  
with\_items: “{{yum\_packages|json\_query(jsonquery)}}”  
vars:  
jsonquery: “results[?name==‘check-mk-raw-{{cmk\_version}}’].name”

how I can use jsonquery var that will grab anything that starts with check-mk-raw so I can test if package name containing check-mk-raw is installed.  
Also what would be the best way to just extract the version/release only. if I use var jsonquery: “results[?name==‘check-mk-raw-{{cmk\_version}}’].name” the result would be check-mk-raw-1.4.0p7. I will need to extract “1.4.0p7” value only

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 30, 2017, 11:24am UTC](https://forum.ansible.com/t/using-json-query-filter/24860/2 "2017-06-30T11:24:11Z")

</div>

I can recommend using the [http://jmespath.org/tutorial.html](http://jmespath.org/tutorial.html) to figure out what your jsonquery needs to be. You can paste your json into any of the example boxes and then tinker with the jsonquery and see the results directly on the webpage.

Hope this helps a bit

Jon

---

<div class="post-metadata">

**Author:** ![Daniel\_JD](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Daniel\_JD](https://forum.ansible.com/u/Daniel_JD)\
**Post date:** [June 30, 2017, 8:19pm UTC](https://forum.ansible.com/t/using-json-query-filter/24860/3 "2017-06-30T20:19:58Z")

</div>

Why not something like:

- name: Check if check\_mk is installed  
shell: ‘yum list installed check-mk-raw-\*’  
register: cmk\_status

- name: Check result  
debug:  
msg: “{{ cmk\_status| ternary( cmk\_status.stdout…[extract version here], “Not installed”) }}”
