Transform an array of strings into an array of objects

Hello! Hopefully a simple one.

I have an array of strings hitting my webhook.

The data in question is

leadSources: [
"One",
"Two"
]

Screenshot 2024-03-02 at 13.39.32

I want to perform a simple transformation of this so I get an array of objects like so:

leadSources: [
   {"name": "One"},
   {"name": "Two"}
]

How might I go about doing this?

For further context:

  1. The Data is coming from a form submission, from a Select element with 2 Options selected.
  2. I am trying to update a Notion page property with the type of “multi-select”. I believe it takes in an array of objects with a key-value pair where “name” key has to be specified.

This is just a case where I’m not familiar enough with make and what it can and can’t do, any help is appreciated!

Please let me know if my question is not specific enough.

Thanks,

Rafal

Hi @Rafal,
The only way I can figure to do this is by using Iterator (on the leadSources array) → Array Aggregator (aggregate just the Value) → Create JSON (custom data structure)

Here is what Iterator (#11) looks like:
image

Followed by an Aggregator (#12) and we aggregate just Value:

And finally, Create JSON (#13)

This is a custom Data Structure where Lead Sources is an array of Collections where each collection contains just a name property of type text. We map the array from aggregator into the Lead Sources field. When you create your Data Structure, use the Generate option and supply this JSON:
{ "leadSources": [ {"name": "One"}, {"name": "Two"} ] }

2 Likes

Beauty. Thank you for teaching me @Donald_Mitchell , I really appreciate it. I had no idea the iterator and aggragator exist. I’ll spend a bit more time on learning their capabilities :slight_smile:

I’ve only ever used JS for this sort of stuff and I was completely stuck trying to recreate that through the logic/tools I was familiar with…

Hi Here is the blueprint
blueprint (3).json (5.7 KB)

Hello there @Rafal welcome to the Make Community :blob_wave:

Fantastic to see that you managed to get this up and running with the expert assistance of @Donald_Mitchell :clap:

Just FYI, you can learn more about iterators and aggregators in our Make Academy, especially in the following course:

2 Likes