Map function returning string instead of array

I am attempting to get some data in the following output format, where all earnings with the same paymentID are grouped together, showing the total payment amount (sum of earnings), as well as all the earningIDs:


Currently I have an iterator, a filter, and then an aggregator set up with group by set to paymentId (this is only where the important bit starts):

This gives me a very nice grouped output:

Now I want to go to the desired format from image 1. The payment ID and total payment amount work fine. The problem I am facing is that I cannot get the earningIds array in the correct format (with the square brackets, commas, and quotation marks). I have tried to use the following:

But this gives me:

This is obviously not a valid json.

I thought this was a stupid mistake at first but then I tried putting the map(38. Array[ ];0) on its own in a variable and I got exactly what I needed (whaaat):


I then tried to just reference this variable in the next module but this also does not work.

In the end, I want to know how I can work with my data without having to worry about stringifying things and then making jsons again. It just seems that I have proper formatted data, which I then waste by turning it into text, then I have to struggle to get it back. Any help on this would be appreciated, whether its trying a completely different approach or just making this one work.

PS, I can send the outputs and flow etc if necessary but I felt like these images explain enough.

Welcome to the Make community!

Please provide the output bundles of each of the relevant modules by running the scenario (you can also get this without re-running your scenario from the History tab).

Click on the white speech bubbles on the top-right of each module and select “Download input/output bundles”.

A. Upload as a Text File

Save each bundle contents in a plain text editor (without formatting) as a bundle.txt file.

You can upload the file here by clicking on this button:

B. Insert as Formatted Code Block

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles.
Here are some ways to provide text content in a way that it won’t be modified by the forum.

  • Method 1: Type code fence manually
    Add three backticks ``` before and after the content/bundle, like this,

    ```
    content goes here
    ```

  • Method 2: Highlight and click the format button in the editor

  • Method 3: Upload your file and share the public link
    (this method is only recommended for large files exceeding the forum upload limit)

Providing the input/output bundles will allow others to replicate what is going on in the scenario, especially if there are complex data structures (nested arrays and collections) or if external services are involved, and help you with mapping the raw property names from collections.

This will allow others to better assist you. Thanks!

Hope this helps! Let me know if there are any further questions or issues. P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!

@samliew

Hi Sam, thanks for the advice. Here is an updated version in the required format:

I am attempting to get some data in the following output format, where all earnings with the same paymentID are grouped together, showing the total payment amount (sum of earnings), as well as all the earningIDs:

[
    {
        "paymentId": "6815102449",
        "paymentAmount": 1015.59,
        "earningIds": [
            "c9a69e7e-d7a5-4d1e-b5a9-b541336c3839",
            "41eadcfc-cb9f-4612-a2ad-8358473dc50e"
        ]
    },
    {
        "paymentId": "6915102553",
        "paymentAmount": 400.69,
        "earningIds": [
            "c9a69e7e-d7a5-4gr23ge-b5a9-b541336c345",
            "41eadcfc-cb9f-46vwfivbijn-8473dc50e"
        ]
    }
]

Currently I have an iterator, a filter, and then an aggregator set up with group by set to paymentId:

This gives me a very nice grouped output (where IMTKEY is paymentId):

[
 {
        "__IMTKEY__": "6815102449",
        "array": [
            {
                "earningId (A)": "c9a69e7e-d7a5-4d1e-b5a9-b541336c3839",
                "earningAmount (S)": "484.03",
                "25": "6815102449"
            },
            {
                "earningId (A)": "41eadcfc-cb9f-4612-a2ad-8358473dc50e",
                "earningAmount (S)": "290.03",
                "paymentId (Z)": "6815102449"
            },
            {
                "earningId (A)": "05e4caa7-53c6-4f19-b3d0-6bbfe9c7b320",
                "earningAmount (S)": "241.53",
                "paymentId (Z)": "6815102449"
            }
        ]
    },
    {
        "__IMTKEY__": "6865073789",
        "array": [
            {
                "earningId (A)": "aaf667f4-2aec-4319-962c-3d2690592572",
                "earningAmount (S)": "290.03",
                "paymentId (Z)": "6865073789"
            }
        ]
    }
]

Now I want to go to the desired format from codeblock 1. The payment ID and total payment amount work fine. The problem I am facing is that I cannot get the earningIds array in the correct format (with the square brackets, commas, and quotation marks). I have tried to use the following in a set variable module:

{
  "paymentId": "{{38.`__IMTKEY__`}}",
  "paymentAmount": {{parseNumber(sum(map(38.array; earningAmount (S))); ".")}},
"earningId": {{map(38.array; earningId (A))}}
}

But this gives me:

[
    {
        "test": "{\n  \"paymentId\": \"6815102449\",\n  \"paymentAmount\": 1015.5899999999999,\n\"earningId\": c9a69e7e-d7a5-4d1e-b5a9-b541336c3839, 41eadcfc-cb9f-4612-a2ad-8358473dc50e, 05e4caa7-53c6-4f19-b3d0-6bbfe9c7b320\n}"
    }
]

This is obviously not a valid json.

I thought this was a stupid mistake at first but then I tried putting the map(38. Array;0) on its own in a set variable:

{{map(38.array; earningId (A))}}

and I got exactly what I needed (whaaat):

[
    {
        "earningId": [
            "c9a69e7e-d7a5-4d1e-b5a9-b541336c3839",
            "41eadcfc-cb9f-4612-a2ad-8358473dc50e",
            "05e4caa7-53c6-4f19-b3d0-6bbfe9c7b320"
        ]
    }
]

I then tried to just reference this variable in the next module but this also does not work.

In the end, I want to know how I can work with my data without having to worry about stringifying things and then making jsons again. It just seems that I have proper formatted data, which I then waste by turning it into text, then I have to struggle to get it back. Any help on this would be appreciated, whether its trying a completely different approach or just making this one work.