# Filter out text from a json object created by an ansible register

**URL:** <https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099>\
**Category:** Ansible Project\
**Created:** [January 30, 2020, 1:38pm UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099 "2020-01-30T13:38:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 30, 2020, 1:38pm UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099/1 "2020-01-30T13:38:17Z")

</div>

Hi,  
How do I take only the text from the below from json created by an ansible register

I have this

- name: Display the query results  
debug:  
msg: “{{ query\_result }}”

and I get [[“TESTDBA”]], I want the value to be TESTDBA. Basically I am passing this value to another parameter in the same playbook like the below

roles: “{{query\_result.msg }}”

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [January 30, 2020, 2:01pm UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099/2 "2020-01-30T14:01:43Z")

</div>

The value you're looking for is the first item of the first list

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ query\_result.0.0 }}"

gives

&nbsp;&nbsp;&nbsp;&nbsp;"msg": "TESTDBA"

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 30, 2020, 7:52pm UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099/3 "2020-01-30T19:52:42Z")

</div>

Hi,  
Thanks for your help. I may be asking a simple question. I am new to ansible, so trying to learn.

This is what I need to understand.

1. Run the below

sql: select grantee FROM DBA\_SYS\_PRIVS where PRIVILEGE=‘INSERT ANY TABLE’ and grantee not like ‘SYS’ and grantee != ‘WMSYS’ and grantee != ‘DBA’ and grantee != ‘IMP\_FULL\_DATABASE’;  
register: query\_result

The query result will be the users in the DB has DBA\_SYS\_PRIVS and it can be more than one.I want to iterate the below task passing the username dynamically.

1. The query\_result have to be iterated in the below

- name: This playbook will grant or revoke privilges in the user.  
oracle\_privs:  
user: “{{user}}”  
password: “{{password}}”  
service\_name: “{{sname}}”  
port: “{{prt}}”  
hostname: “{{hostname}}”  
privs:
- INSERT ANY TABLE  
state: absent  
**roles: “{{ query\_result }}”**  
quiet: false  
environment: “{{oracle\_env}}”  
register: user\_privs  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 30, 2020, 8:20pm UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099/4 "2020-01-30T20:20:38Z")

</div>

The result I get from the query\_result is something like this [[“TESTDBA”], [“TESTDBA2”]]

I want to know how to pass this variable removing the square brackets and the **roles** in the task

---

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 31, 2020, 4:27am UTC](https://forum.ansible.com/t/filter-out-text-from-a-json-object-created-by-an-ansible-register/32099/5 "2020-01-31T04:27:23Z")

</div>

Just this made the trick. Thanks very much

roles: “{{item}}”  
quiet: false  
environment: “{{oracle\_env}}”  
register: user\_privs  
with\_items : “{{query\_result.msg}}”
