How to extract the values of multiple collections within array

My attempt is to create formatted meal plans from an API output (Spoonacular). After parsing a JSON string using the “Parse JSON” module, I want to format the output to the following for each day:

[Day]:
Meal Name: [Meal Title]
Serving(s): [Number of servings]
Ready in: [Preparation time] minutes
Source URL: [URL]

Meal Name: [Meal Title]
Serving(s): [Number of servings]
Ready in: [Preparation time] minutes
Source URL: [URL]

Meal Name: [Meal Title]
Serving(s): [Number of servings]
Ready in: [Preparation time] minutes
Source URL: [URL]

Overall Nutritional Information:
Calories: [Total calories]
Protein: [Total protein]g
Fat: [Total fat]g
Carbohydrates: [Total carbohydrates]g

The nutritional information is quite easy to extract as there is only one collection for each day, although “meals[ ]” contains 3 meals which are in three separate collections, when I try iterate the whole output I’m unable to retrieve all seperate meals correctly, it just shows me the values you’d expect to see in a meal e.g “id” “imageType” “title” etc.

Here is the json file:
out.json (10.0 KB)

Thanks!

Welcome to the Make community!

Please provide the output bundles of the “Parse JSON” module by running the scenario, then click the white speech bubble on the top-right of each module (like in your screenshot), save the contents as a text (.json) file, and upload it here into this discussion thread:
Screenshot_2023-10-06_141025

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

1 Like

Thanks for your feedback!

out.json (10.0 KB)

Here’s one way of doing it:

blueprint.json (16.6 KB)

Output:

Thank you so much!!

Quick question, I see in the second iterator, you iterate through the meals using a mapping from the output of the first iterator. Although, there is no direct mapping for it. How did you map “value.meals”?

Manually type {{3.value.meals}} into the box. Change “3” to the module number if it’s different for you.

3 Likes

Everything seems to be functioning correctly, thanks to you. Although when it transfers the meal plans over to the g sheet, instead of doing it in one cell, for each day it uses a new cell.

e.g Monday - A1, Tuesday - A2, Wednesday A3

If you want to combine all the bundles together into a single value/bundle/cell, you can use another Text Aggregator. Set Source Module to the “Iterate Days” iterator module.

3 Likes