# Extract unique dictionary item from json

**URL:** <https://forum.ansible.com/t/extract-unique-dictionary-item-from-json/35017>\
**Category:** Ansible Developer\
**Created:** [April 20, 2021, 12:11pm UTC](https://forum.ansible.com/t/extract-unique-dictionary-item-from-json/35017 "2021-04-20T12:11:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![janaki\_raman](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@janaki\_raman](https://forum.ansible.com/u/janaki_raman)\
**Post date:** [April 20, 2021, 12:11pm UTC](https://forum.ansible.com/t/extract-unique-dictionary-item-from-json/35017/1 "2021-04-20T12:11:35Z")

</div>

Hi All,

I am trying create logical volume group and need to get the vg name and device list from the json variable.. i am not sure what is the logic i need to use to get the desired result..

Below is the current output:

{  
“msg”: [  
{  
“vg\_hana\_data”: “/dev/sdf”  
},  
{  
“vg\_hana\_data”: “/dev/sdg”  
},  
{  
“vg\_hana\_data”: “/dev/sdh”  
},  
{  
“vg\_hana\_log”: “/dev/sdi”  
},  
{  
“vg\_hana\_log”: “/dev/sdj”  
}  
]  
}

Here is my code:

- name: Filesystem data gather from input file  
set\_fact:  
fs: “{{jsondata | json\_query(jmesquery) }}”  
vars:  
jmesquery: ‘filesystem[\*].{hostname:hostname,devicename:Devicename,path:MountPath,type:FileSystemType,owner:FSOwner,group:FSGroup,vgname:vgname}’
- name: creating dictionary to store vgname  
set\_fact:  
#diskdata: “{{ diskdata|default({})|combine ([{item.vgname: item.devicename}]) }}”  
diskdata: “{{ diskdata|default() + [{item.vgname: item.devicename}] }}”

# vg\_dict: “{{vg\_dict|combine( {item.vgname : item.path}) }}”

with\_items:

- “{{fs}}”  
when: “‘{{item.vgname}}’.startswith(‘vg\_hana’)”
- name:  
debug:  
msg: “{{diskdata}}”
- name: Appending data variable  
set\_fact:  
hana\_data: “{{hana\_data}} + [‘{{item.vgname}}’]”  
with\_items: “{{fs}}”  
when: “‘{{item.vgname}}’.startswith(‘vg\_hana’)”  
vars:  
hana\_data: 
- debug:  
msg: “{{hana\_data}}”

Badly need some help on this.
