Formatting Array Items

If I have an arrays of items like:

{
    "Away": [
        32b5edf9-b8a6-426e-b860-7e7116dd2b10,
        c41f69ae-e542-4095-934d-04511699aaad
    ],
    "Preference": [
        14ee157f-98bf-4f70-b092-eea9eaa759e1
    ]
}

How can wrap the items in each array in speechmarks, without iterating through each separate array and using a text aggregator to do that? There must be a simple way to apply some formatting to the items in each array?

The output should be:

{
    "Away": [
        "32b5edf9-b8a6-426e-b860-7e7116dd2b10",
        "c41f69ae-e542-4095-934d-04511699aaad"
    ],
    "Preference": [
        "14ee157f-98bf-4f70-b092-eea9eaa759e1"
    ]
}

I’m extracting the list of IDs that populate each array in a map() function so if I can add the speechmarks while extracting the IDs, that’d also solve my problem.

Ultimately, I need to send the arrays as valid JSON in a webhook response.

Hi!

If I understand it well, you are getting this JSON file (with an incorrect format) as a String and you want to add the speechmarks before you can return it in the payload of your webhook response?

How did you get this json? Maybe there is something we can do before to avoid this format?
If ever it’s not possible to correct this initial data, we could still use regular expressions to correct it.

I can try and help you with it

Benjamin

1 Like

Thanks for the quick reply!

The json is coming from a list of Notion page IDs that I’ve fetched in a previous step, which I then aggregate into groups of arrays in an array aggregator step.

Maybe you could use a Text Aggregator instead of the Array aggregator so that you have more control over the Json doc you want to build. I’m just wondering, you have 2 arrays in your document; does it mean you have to generate the 2?

And if ever there is no simple way to do it; I have an ugly solution with replace functions and regex. I started to test, it’s possible we can do it combining 3 replace functions, but I need to see the raw JSON that you get. The one you give here seems to have extra carriage returns.

So, eventually, can you show me more how you have generated the first JSON (I mean before the set Variable), and/or can you send a raw version of the JSON you are trying to correct, so that I can try with regex?

Benjamin

4 Likes

Thanks for the suggestion, that worked!

1 Like