How do I convert an array to a JSON?

Hi folks,

Ok the title is a bit simplistic, but I’m so close to solving something and I just can’t seem to get the final piece done.

I’m encountering an issue while trying to build a JSON payload in the Create JSON module. Despite correctly formatting the data in a previous module, the value for one of my keys (SalesEntryLines) is being transformed into [Collection], [Collection] instead of the expected JSON array.

This is the structure I’m aiming for:

{
    "fields": [
        {
            "key": "Customer",
            "value": "2d53c052-b48c-4101-be88-dabfb1adbe4c"
        },
        {
            "key": "Journal",
            "value": "40"
        },
        {
            "key": "Currency",
            "value": "USD"
        },
        {
            "key": "Rate",
            "value": 1.5
        },
        {
            "key": "SalesEntryLines",
            "value": [
                {
                    "Asset": "0c3236d2-65dc-41c3-a9ce-dfb1b62487dc",
                    "Notes": "167285 Still RX-60-25",
                    "VATCode": "6",
                    "AmountFC": 12500,
                    "Quantity": 1,
                    "AssetDescription": "167285 Still RX-60-25"
                },
                {
                    "Asset": "0c3236d2-65dc-41c3-a9ce-dfb1b62487dc",
                    "Notes": "168550 Toyota SWE-120",
                    "VATCode": "6",
                    "AmountFC": 15000,
                    "Quantity": 1,
                    "AssetDescription": "168550 Toyota SWE-120"
                }
            ]
        }
    ]
}

But what I keep getting is this:

{
    "fields": [
        {
            "key": "Customer",
            "value": "2d53c052-b48c-4101-be88-dabfb1adbe4c"
        },
        {
            "key": "Journal",
            "value": "40"
        },
        {
            "key": "Currency",
            "value": "USD"
        },
        {
            "key": "Rate",
            "value": "1.5"
        },
        {
            "key": "SalesEntryLines",
            "value": "[Collection], [Collection]"
        }
    ]
}

These are the modules:

Output from the Array Aggregator:

Configuration of the Set Variable module:

Output from the Set Variable module:

Configuration of the Create JSON module:

I’ve tried a ton of different stuff to get the Create JSON module to just take the flat input as JSON, but I keep running into a wall and am about to pull my hair out. Can anyone advise?

It looks like you’ve just gone too deep with the mapping, if the transformed JSON in the set variable module has the structure that you want, you should copy the output as a named array {SalesEntryLines: object} and then you can just map the array without setting each of the fields individually.

Basically it looks like your defined output is an object rather than the correct array of objects.

Hey, I’m not sure what you mean with “copy the output as a named array”.

This is what I tried initially, seemed easier than Creating JSON and then using the Map slider on the Fields property here:

But it gives the same result. [Collection],[Collection] instead of the actual JSON. So I figured, with the Map slider turned on I have more control over the JSON that I pass in. But I can’t seem to figure it out.

So you should try and get it to map the array not the fields.

The schema is of an object, it needs to be an array then you can choose the output array to map it all.

I’ve uploaded an example, the key is the schema is of a single array, not the objects…

@systemprompt.io So that is what I tried initially, just mapping the result of the Array aggregator. But it gives me the same result: [collection],[collection]. I’ve recorded a video that hopefully gives some more clarity:

Make.com - Array issue?

Hi @Bob_Balm, I watched your video.

Sorry, but it seems the complication is with how Integr has developed their Community App, and not necessarily an easy Make question. In Exact Online, if you want to generate a new invoice and send this to the customer, then SalesInvoices is the correct endpoint. But if you just want to record the value of invoice in Exact online, then SalesEntries is the correct endpoint to use to update Exact Online, so this should be included in their app. It also appears that the Universal module of the app doesn’t follow the normal practice of allowing you to build your own request Body, instead using the “fields” collection.

I have a few suggestions to try though:

  • Instead of the Create JSON module, did you try the “Transform to JSON” module, which will convert the array from your array aggregator into a JSON string, which you can then map directly into the Exact “universal” module?
  • If that doesn’t work: In the Exact “universal” module, set the slider next to the word “fields” to “Map” and experiment with creating your own data structure to send to the API.

You may have to format this data structure as
[{ "key": "Customer", "value": "{{MAPPED_FROM_WEBHOOK}}" }, { "key": "Currency", "value": "{{MAPPED_FROM_WEBHOOK}}" }, { "key": "SalesEntryLines", "value": {{MAPPED_FROM_Transform_to_JSON_MODULE}} }]
OR it may allow:
{ "Customer": "{{MAPPED_FROM_WEBHOOK}}", "Currency": "{{MAPPED_FROM_WEBHOOK}}", "SalesEntryLines": {{MAPPED_FROM_Transform_to_JSON_MODULE}} }

Let us all know how it goes.

Regards, Terry.