# Parsing json output from uri module

**URL:** <https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537>\
**Category:** Ansible Project\
**Created:** [January 26, 2019, 4:04pm UTC](https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537 "2019-01-26T16:04:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Owens](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@Tony\_Owens](https://forum.ansible.com/u/Tony_Owens)\
**Post date:** [January 26, 2019, 4:04pm UTC](https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537/1 "2019-01-26T16:04:12Z")

</div>

I’m trying to parse the output of a uri request that I have saved in a variable named “apis”. Ultimately i will want to match several items when AnonymousAccessAllowed=true but I’m not having success. Any help would be appreciated.

If i debug “{{apis.json}}” this is the output.

`

TASK [debut apis] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [localhost] =\> {

“msg”: {

“APIImplementationInfo”: [

{

“APIOwnedImplementation”: true,

“APIVersionID”: “799285b2-ac87-44be-8f61-342b96ffba2c.travelportAPI”,

“AnonymousAccessAllowed”: false,

“EndpointAccessAutoApproved”: true,

“ImplementationCode”: “Live”,

“Pattern”: “com.akana.pattern.proxy”,

“ServiceKey”: “uddi:5988b66a-ff7f-11e6-8674-d0288b15863d”

},

{

“APIOwnedImplementation”: true,

“APIVersionID”: “799285b2-ac87-44be-8f61-342b96ffba2c.travelportAPI”,

“AnonymousAccessAllowed”: true,

“EndpointAccessAutoApproved”: true,

“ImplementationCode”: “Sandbox”,

“Pattern”: “com.akana.pattern.proxy”,

“ServiceKey”: “uddi:3ebe224d-506b-11e7-ba06-98021d1b1c3f”

}

]

}

}

`

This is the relevant parts of the playbook. I’ve commented out the when condition but get an undefined variable in the test task.

`

- name: debut apis

debug:

msg: “{{apis.json}}”

- name: init fact

set\_fact:

anon: “”

- name: test

set\_fact:

anon: “{{anon}} + [{{item.AnonymousAccessAllowed}}]"

#when: item.AnonymousAccessAllowed | search(“true”)

with\_items: “{{apis.json.APIImplementationInfo}}”

- name: output

debug:

msg: “{{anon}}”

`

---

<div class="post-metadata">

**Author:** ![Tony\_Owens](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@Tony\_Owens](https://forum.ansible.com/u/Tony_Owens)\
**Post date:** [January 29, 2019, 1:50pm UTC](https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537/2 "2019-01-29T13:50:08Z")

</div>

If anyone has a suggestion I’d appreciate it. This is driving me bonkers and i’m sure I am missing some basic understanding.

Thanks

---

<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:** [January 29, 2019, 2:51pm UTC](https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537/3 "2019-01-29T14:51:37Z")

</div>

Probably something such as:

- debug:  
msg: “{{ apis.json.APIImplementationInfo|selectattr(‘AnonymousAccessAllowed’)|list }}”

---

<div class="post-metadata">

**Author:** ![Tony\_Owens](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@Tony\_Owens](https://forum.ansible.com/u/Tony_Owens)\
**Post date:** [January 30, 2019, 3:10am UTC](https://forum.ansible.com/t/parsing-json-output-from-uri-module/29537/4 "2019-01-30T03:10:02Z")

</div>

Thanks for the reply Matt but debugging with that option lends:

TASK [output] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [localhost]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘APIImplementationInfo’\n\nThe error appears to have been in ‘/Users/tony/foo2.yml’: line 40, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: output\n ^ here\n”}
