# JSON Query Filter Help

**URL:** <https://forum.ansible.com/t/json-query-filter-help/26753>\
**Category:** Ansible Project\
**Created:** [February 15, 2018, 10:28pm UTC](https://forum.ansible.com/t/json-query-filter-help/26753 "2018-02-15T22:28:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [February 15, 2018, 10:28pm UTC](https://forum.ansible.com/t/json-query-filter-help/26753/1 "2018-02-15T22:28:24Z")

</div>

I have a task that hits a url and returns the results in JSON array like this:

1. 

> “json”: {  
> “statuses”: [  
> {  
> “application”: “JIRA”,  
> “completeKey”: “com.atlassian.jira.plugins.jira-healthcheck-plugin:hsqlHealthCheck”,  
> “description”: “Checks if the instance is connected to an HSQL or H2 database”,  
> “documentation”: “[https://confluence.atlassian.com/x/1guaEQ](https://confluence.atlassian.com/x/1guaEQ)”,  
> “failureReason”: “You are not using an HSQL or H2 embedded database with a production license.”,  
> “healthy”: true,  
> “id”: 0,  
> “isHealthy”: true,  
> “name”: “Embedded database”,  
> “severity”: “undefined”,  
> “tag”: “Supported Platforms”,  
> “time”: 1518726326309  
> },  
> {  
> “application”: “JIRA”,  
> “completeKey”: “com.atlassian.jira.plugins.jira-healthcheck-plugin:eolHealthCheck”,  
> “description”: “Checks if the running version of JIRA is approaching, or has reached End of Life.”,  
> “documentation”: “[https://confluence.atlassian.com/x/HjnRLg](https://confluence.atlassian.com/x/HjnRLg)”,  
> “failureReason”: “Unable to verify the End of Life date for version ‘7.4.x’. The check has not been performed.”,  
> “healthy”: true,  
> “id”: 0,  
> “isHealthy”: true,  
> “name”: “End of Life”,  
> “severity”: “undefined”,  
> “tag”: “Supported Platforms”,  
> “time”: 1518726326316  
> },  
> {  
> “application”: “JIRA”,  
> “completeKey”: “com.atlassian.jira.plugins.jira-healthcheck-plugin:luceneSupportHealthCheck”,  
> “description”: “Checks the state of the search index is consistent with the database.”,  
> “documentation”: “[https://confluence.atlassian.com/x/9IUfL](https://confluence.atlassian.com/x/9IUfL)”,  
> “failureReason”: “The issue index is inconsistent with the database state.”,  
> “healthy”: false,  
> “id”: 0,  
> “isHealthy”: false,  
> “name”: “Lucene”,  
> “severity”: “major”,  
> “tag”: “Indexing”,  
> “time”: 1518726326372  
> },

The two tasks that run looks like this:

`

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 15, 2018, 10:37pm UTC](https://forum.ansible.com/t/json-query-filter-help/26753/2 "2018-02-15T22:37:49Z")

</div>

Honestly, I try to stay away from json\_query when possible, and stick to just standard jinja2 pipelines:

“{{ (results.json.statuses|selectattr(‘name’, ‘match’, ‘Lucene’)|list|first).isHealthy }}”

You can use a variety of tests instead of `match`, such as `search` or `equalto`.

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [February 15, 2018, 11:50pm UTC](https://forum.ansible.com/t/json-query-filter-help/26753/3 "2018-02-15T23:50:28Z")

</div>

@Matt - that worked perfectly. I’m assuming that the jinja2 pipeline you added as a sample works as follows:

It pipes the results from my results variable grabbing only the json.statuses data structure, selects the attribute **name** that matches the value **Lucene** and from that data structure or position, look for the first **isHealthy** key and give me only that result. Do I have that correct?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 15, 2018, 11:51pm UTC](https://forum.ansible.com/t/json-query-filter-help/26753/4 "2018-02-15T23:51:06Z")

</div>

That is correct.
