# Having difficulty using a generator? object?

**URL:** <https://forum.ansible.com/t/having-difficulty-using-a-generator-object/21065>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [April 5, 2016, 1:00am UTC](https://forum.ansible.com/t/having-difficulty-using-a-generator-object/21065 "2016-04-05T01:00:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![J\_Norment](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@J\_Norment](https://forum.ansible.com/u/J_Norment)\
**Post date:** [April 5, 2016, 1:00am UTC](https://forum.ansible.com/t/having-difficulty-using-a-generator-object/21065/1 "2016-04-05T01:00:11Z")

</div>

Would like to be able to check contents of json.items._.labels[_] and json.items._.labels[_].value from json below:

I’m unsure how to get the contents of the generator from ansible / jinja2.

- name: Test json  
debug: “msg={{ json.items|map(attribute=‘metadata’) }}”

$ ansible-playbook -i inv/dev k8s-redis.yml --extra-vars “@test-var.json”

Gives me:

TASK [k8s-redis : Test json] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [aus-ared-dev-00] =\> {  
“msg”: “\<generator object do\_map at 0x224de60\>”  
}

This is the json:

{“json”: {  
“apiVersion”: “v1”,  
“items”: [  
{  
“metadata”: {  
“creationTimestamp”: “2016-03-22T18:18:48Z”,  
“labels”: {  
“[kubernetes.io/hostname](http://kubernetes.io/hostname)”: “aus-akn-dev-00.q2dc.local”  
},  
“name”: “aus-akn-dev-00.q2dc.local”,  
“resourceVersion”: “557645”,  
“selfLink”: “/api/v1/nodes/aus-akn-dev-00.q2dc.local”,  
“uid”: “85b7ae17-f05a-11e5-b8a3-005056bc5b54”  
}  
},  
{  
“metadata”: {  
“creationTimestamp”: “2016-03-23T19:49:22Z”,  
“labels”: {  
“[kubernetes.io/hostname](http://kubernetes.io/hostname)”: “aus-akn-dev-01.q2dc.local”  
},  
“name”: “aus-akn-dev-01.q2dc.local”,  
“resourceVersion”: “557644”,  
“selfLink”: “/api/v1/nodes/aus-akn-dev-01.q2dc.local”,  
“uid”: “57306016-f130-11e5-975f-005056bc5b54”  
}  
}  
]  
}}

I’ve tried |to\_json, |from\_json, |list, combinations of the preceding, and even building custom filters to try to work with the generator object directly.

---

<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:** [April 5, 2016, 2:49am UTC](https://forum.ansible.com/t/having-difficulty-using-a-generator-object/21065/2 "2016-04-05T02:49:44Z")

</div>

There are likely a few problems. The first is that `items` has a naming collision with the .items() method of a python dictionary, so you need to use `json['items']` instead.

After that, you will also likely need to use the |list filter too. So something like:

json[‘items’]|map(attribute=‘metadata’)|list
