Templating list help

Forgive me, I’m having a bit of issue trying to get a response variable from a mealie Integration service into a list.

The response variable outputs the following (name of variable is Today):

mealplan:
    - mealplan_id: 561
      user_id: fdfb4652-daa3-4d91-ac97-a8673c5b0806
      group_id: 65082ac2-0329-4859-9515-173c8c3687fe
      entry_type: dinner
      mealplan_date:
        __type: <class 'datetime.date'>
        isoformat: '2025-02-08'
      title: null
      description: null
      recipe:
        recipe_id: 47b263b1-5d1b-4c19-8057-c3989fdd0fe4
    - mealplan_id: 561
      user_id: fdfb4652-daa3-4d91-ac97-a8673c5b0806
      group_id: 65082ac2-0329-4859-9515-173c8c3687fe
      entry_type: dinner
      mealplan_date:
        __type: <class 'datetime.date'>
        isoformat: '2025-02-08'
      title: null
      description: null
      recipe:
        recipe_id: 47c263b1-5d1b-4c29-8057-c3989fcd0fe4

I’m looking to parse the output of this variable into a list with only the mealplan.recipe.recipe_id. Below is what I have so far. I can’t seem to get past this point regardless of what I try.

variables:
  recipeid: |
    {%- for value in Today['mealplan'] %}
      {%- for recipe in value['recipe'] %}
        {{ recipe }}
      {%- endfor %}
    {%- endfor %}
variables:
  recipeid: |
    {{ Today['mealplan'] | map(attribute='recipe') | map(attribute='recipe_id') | list  }}

FYI

You can consolidate the two map filters.

    {{ Today['mealplan'] | map(attribute='recipe.recipe_id' | list }}

FWIW, I didn’t think it was possible but proved it works by testing the following example in the Template Editor.

{% set x = [
{'y': 4, 'recipe': {'recipe_id': 'cat'}},
{'y': 5, 'recipe': {'recipe_id': 'hat'}}
] %}

{{ x | map(attribute='recipe.recipe_id') | list }}
1 Like

Sigh… I have to say that I was confused by the map filter in other queries but now that I see it used here, I’m glad I asked. Thank you both for the help!

map() is super useful but it can be confusing since it has 2 uses that don’t seem related at first.