# Handling REST API output with json\_query

**URL:** <https://forum.ansible.com/t/handling-rest-api-output-with-json-query/35393>\
**Category:** Ansible Developer\
**Created:** [June 22, 2021, 6:41pm UTC](https://forum.ansible.com/t/handling-rest-api-output-with-json-query/35393 "2021-06-22T18:41:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Cifelli](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mike\_Cifelli](https://forum.ansible.com/u/Mike_Cifelli)\
**Post date:** [June 22, 2021, 6:41pm UTC](https://forum.ansible.com/t/handling-rest-api-output-with-json-query/35393/1 "2021-06-22T18:41:49Z")

</div>

Seeking assistance with properly parsing returned json data, storing desired string as variable, to then append it in another play that updates a resource. Essentially I am interacting with Cisco ISE APIs to manage/update endpoint attributes. Overview of playbook:

-The first play is a GET query to provide me with a specific endpoint details

-The next play prints the returned output essentially showing the admin that everything is good thus far

-Then I extract the endpoint ID string using json\_query and store it as a variable

-For peace of mind the following play prints the variable to show we have the ID string of the endpoint

-Then the last play I attempt to update the endpoint group assignment via appending the id string

I am stuck on the last play that appends the endpoint id string. Play using json\_query:

- name: Get ISE ID String

set\_fact:

id: “{{ endpoint\_id | json\_query(jmesquery) }}”

vars:

jmesquery: ‘_.SearchResult.resources[_].id’

Tower output showing how the id string is being appended:

“status”: 400, “url”: “[https://xx.xx.xx.xx:9060/ers/config/endpoint/[[u’69d3bf30-ce12-11eb-ba90-c63c5470e9ab’]](https://xx.xx.xx.xx:9060/ers/config/endpoint/%5B%5Bu'69d3bf30-ce12-11eb-ba90-c63c5470e9ab'%5D)]”

How can I properly store/append the endpoint id string properly so that the url in my last play looks like this:

“status”: 400, “url”: “[https://xx.xx.xx.xx:9060/ers/config/endpoint/69d3bf30-ce12-11eb-ba90-c63c5470e9ab](https://xx.xx.xx.xx:9060/ers/config/endpoint/69d3bf30-ce12-11eb-ba90-c63c5470e9ab)”

Please advise. TIA!

---

<div class="post-metadata">

**Author:** ![Mike\_Cifelli](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mike\_Cifelli](https://forum.ansible.com/u/Mike_Cifelli)\
**Post date:** [June 23, 2021, 6:16pm UTC](https://forum.ansible.com/t/handling-rest-api-output-with-json-query/35393/2 "2021-06-23T18:16:06Z")

</div>

Here is the solution:

- name: Extract ID from Nested List  
set\_fact: id: “{{ id[0][0] }}”
