# How can I "slim down" a complex loop result?

**URL:** <https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427>\
**Category:** Get Help\
**Tags:** data\
**Created:** [March 31, 2025, 4:24am UTC](https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427 "2025-03-31T04:24:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![halloleo](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@halloleo](https://forum.ansible.com/u/halloleo)\
**Post date:** [March 31, 2025, 4:24am UTC](https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427/1 "2025-03-31T04:24:06Z")

</div>

When I run the following action:

```
    - name: Find extension file names from given starting string patterns
      ansible.builtin.find:
        paths: /my/dir/with/vsix_file
        patterns: "{{ item }}*.vsix"
      register: found_vsixs
      loop:
        - alefragnani.Bookmarks
        - bradzacher.vscode-copy-filename
        - streetsidesoftware.code-spell-checker
        - pucelle.run-on-save
        ...

```

`found_vsixs` contains a list of complex dictionaries. In each `item` of this list the relevant information is in `item.files[0].path`.

How can I create via Ansible a new variable which only contains a list of these paths without all the other invocation details?

(This would have the advantage that in subsequent steps I don’t have all the unnecessary information in my log, etc.)

Many thanks for any pointers!

---

<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:** [March 31, 2025, 6:58am UTC](https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427/2 "2025-03-31T06:58:47Z")

</div>

Use the filter json\_query

```yaml
files_vsix: "{{ found_vsixs.results | json_query('[].files[].path') }}"

```

---

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [March 31, 2025, 7:53am UTC](https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427/3 "2025-03-31T07:53:42Z")

</div>

Note that you need [community.general](https://galaxy.ansible.com/ui/repo/published/community/general/) collection for the [json\_query](https://docs.ansible.com/ansible/latest/collections/community/general/json_query_filter.html) filter.

If you installed `ansible-core` you may need to install it manually.

Alternative approach with ansible core filters:

```auto
files_vsix: "{{ found_vsixs.results | map(attribute='files') | flatten | map(attribute='path') }}"

```

---

<div class="post-metadata">

**Author:** ![halloleo](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@halloleo](https://forum.ansible.com/u/halloleo)\
**Post date:** [April 1, 2025, 7:50am UTC](https://forum.ansible.com/t/how-can-i-slim-down-a-complex-loop-result/41427/4 "2025-04-01T07:50:23Z")

</div>

Cool

```auto
files_vsix: "{{ found_vsixs.results | map(attribute='files') | flatten | map(attribute='path') }}"

```

[/quote]

Thanks a lot! I’ll try it with the core filters.
