# How to filter data from ansible json format output for a specific element

**URL:** <https://forum.ansible.com/t/how-to-filter-data-from-ansible-json-format-output-for-a-specific-element/28765>\
**Category:** Ansible Project\
**Created:** [October 11, 2018, 9:18am UTC](https://forum.ansible.com/t/how-to-filter-data-from-ansible-json-format-output-for-a-specific-element/28765 "2018-10-11T09:18:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhijith.devaraju](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@abhijith.devaraju](https://forum.ansible.com/u/abhijith.devaraju)\
**Post date:** [October 11, 2018, 9:18am UTC](https://forum.ansible.com/t/how-to-filter-data-from-ansible-json-format-output-for-a-specific-element/28765/1 "2018-10-11T09:18:10Z")

</div>

Hello All,

I am using API call to fetch some data in json format. I would like to use/filter only part of data for my further tasks. Can someone help me out in filtering the json format for the element ?

**API call response data in JSON format:**

{“changed”: false, “connection”: “close”, “set\_cookie”: “JSESSIONID=B34ADACAE187BBA06C265A478F8565D0; Path=/; Secure; HttpOnly”, “status”: 200}

**Debug task:**

register: login

- debug:  
msg: “{{ login.set\_cookie }}”

login------- This is the register name which I am using to register the api call response in step1.

**Current Output for debug task:**

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “JSESSIONID=83FC7E3849EEC229A9999FC4015C0DAB; Path=/; Secure; HttpOnly”  
}

**Desired Output for debug task:**

ok: [localhost] =\> {  
“msg”: “JSESSIONID=83FC7E3849EEC229A9999FC4015C0DAB”  
}

Basically I need to get rid of the string after ‘;’ which is “ **; Path=/; Secure; HttpOnly** ” from the register output. I am not sure how to filter to get the desired out

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 11, 2018, 9:34am UTC](https://forum.ansible.com/t/how-to-filter-data-from-ansible-json-format-output-for-a-specific-element/28765/2 "2018-10-11T09:34:38Z")

</div>

{{ login.set\_cookie.split(';')[0] }}

---

<div class="post-metadata">

**Author:** ![abhijith.devaraju](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@abhijith.devaraju](https://forum.ansible.com/u/abhijith.devaraju)\
**Post date:** [October 11, 2018, 10:06am UTC](https://forum.ansible.com/t/how-to-filter-data-from-ansible-json-format-output-for-a-specific-element/28765/3 "2018-10-11T10:06:24Z")

</div>

That worked. Looks like the syntax is same as python.  
Thanks a lot Kai Stian Olstad for your quick response.
