Convert array of [tag1, tag2, tag3] into json {"tags":["tag1","tag2","tag3"]}

I hate getting stuck on such basic things but I’m having troubles putting an array into a JSON output.

:star_struck: The goal is to convert array of [tag1, tag2, tag3] into json {“tags”:[“tag1”,“tag2”,“tag3”]}

This is the array output:

Then I want to send a JSON string to another API. The API is expecting: {“tags”:[“tag1”,“tag2”,“tag3”]}

There is something I’m not getting with the translation.

I’ve tried using this in the API JSON field: {“tags”: {{98.output}}}
But this gives me: {“tags”: tag1, tag2, tag3} (no quotations)

:face_with_open_eyes_and_hand_over_mouth: I’ve also tried “Aggregate to JSON” but output is putting the whole thing in square brackets:

:eyes: If it helps to see the Data Structure setup, I created this structure to handle the tags:

Any thoughts on a simple translation like this?

1 Like

@Tom_Hudock you could check the following two approaches:

  1. Using an iterator and then change the format of each of the values after the iterator, which changes it for each value of the array. After doing that, use an aggregator. This costs a good amount of operations (+1 for each value in the array), though.
  2. Transform an array of objects
1 Like

@Tom_Hudock

If you are having only issue of square braclet by using aggregate to json, then you can just use functions to remove that in your next module where you are using this output.

i.e {{substring(output;1;length(output)-1)}}

Regards,
Msquare Automation - Platinum Partner of Make
@Msquare_Automation

1 Like

Thanks @Juliusforster and @Msquare_Automation for your thoughts on this. :partying_face: :brain: Both of your options gave me things to work with and find a solution that works. Thank you for looking at this!

Here’s what I ended up doing (in case this helps someone reading this)…

  1. I used these three modules to produce 2 different output structures based on the same data: array and JSON.

  2. The Array output from the Switch had the array format like this:

  3. The JSON output used the Create JSON module to create the second output in JSON:

  4. The aggregator was also needed to complete the JSON output.

In hindsight, if the modules and HTTP requests later in the scenario were designed differently, I probably wouldn’t have needed both an Array and JSON. But this approached seemed easier to change.

Thanks Make Community!

3 Likes

Hi @Tom_Hudock

Glad to know the issue is solved

Best regards,

Msquare Automation
Platinum Partner of Make
@Msquare_Automation