We often encounter complex JSON payloads that need to be transformed before being sent to another system. This is a common challenge when working with APIs that return detailed, multi-bundle responses, but the receiving system expects a simpler, more focused structure.
Today, we'll walk through a practical example using Make to solve this exact problem. We'll take a JSON payload containing multiple bundles, each with various fields, and transform it into a streamlined array of objects.
This guide is perfect for developers, data analysts, and automation specialists who frequently work with APIs and need to massage data between systems. By the end of this post, you'll have a clear understanding of how to use Make's powerful modules to transform complex JSON structures efficiently.
Step 1: Retrieving the Initial JSON Payload
First, use the HTTP/SOAP module to retrieve your initial payload with 10 bundles.
Step 2: Iterating Through Bundles
Use the Iterator module to process each bundle individually.
Step 3: Parsing Json
Step 4: Extracting Name from Each Bundle
Inside the Iterator, we'll extract the Name from each bundle.
Use a Set Multiple Variables module
Note: We don't tend to use set variable as you can set one variable with the Set Multiple Variables module and it also gives you the ability to expand, save yourself some extra rework in the future and use the multiple option module
Step 5: Aggregating Names
After the Iterator, use a text aggregator module to collect all the Names.
This will create an array of objects, each with a "name" key.
Step 6: Formatting the Final JSON Payload
Now, use the Set Multiple Variables module to structure your data into the desired format.
Step 7: Sending the New Payload
Finally, use another HTTP module to send this new payload to your desired endpoint.
- Method: POST (or whatever method your API requires)
- URL: Your target endpoint
Key Points to Remember
1. The Iterator breaks down the initial payload into individual bundles.
2. We extract just the needed node from each bundle.
3. The text aggregator collects all these nodes into a single array of objects.
4. If you add a module such as parse json before your HTTP module you will create an iteration and the http module will be called as many times as you have bundles
This approach allows you to transform the initial complex payload into a simplified array of objects, ready to be sent to another endpoint.
Whether you're integrating disparate APIs, cleaning up data for analysis, or building complex automation workflows, mastering these techniques in Make will make you more efficient and effective in your data processing tasks.
Comments