Issue with Text Aggregator and #map for JSON Array Creation

Hi everyone,

I’m trying to create a JSON array using the Text Aggregator to group messages retrieved from a Data Store > Search Records module. Here’s my situation:

Context:

  1. The Data Store returns multiple bundles with Role and Message fields, which are visible in the Debug Panel.
  2. I want to format the output like this:
[
  { "role": "user", "content": "Message 1" },
  { "role": "assistant", "content": "Message 2" }
]

Problem:

I keep getting errors like:

  • '{object}' is not a valid array
  • Invalid reference in parameter.

I’ve tried different references (21, 21.records, 21[].Record), but nothing works.

Question:

How can I configure the Text Aggregator (or another module) to produce a JSON array grouping the bundles returned by the Data Store?

I’m a complete beginner and have been using Make for just a week, so I might be missing something basic.

Thanks in advance for your help!

Hello @MakeUser123,
Welcome to the community.

By default, Text Aggregator always returns data in text format.


Instead of Text Aggregator use the Parse JSON module.

Also used to store that array on some of the keys, which is a best practice and makes it easy to use on the next module.
Add these into your Parse JSON module. Change the content value accordingly.
Example:

{
    "arr":[
        { "role": "user", "content": "Message 1" },
        { "role": "assistant", "content": "Message 2" }
    ]
}

I hope this works :+1:

Instead of Text Aggregator, use an Array Aggregator.

Aggregators

Every result (item/record) from iterator/list/search/match modules will output a bundle. This can result in multiple bundles, which then trigger multiple operations in future modules (one operation per bundle). To “combine” multiple bundles into a single variable, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and can apply to many use-cases like building of JSON, CSV, HTML.

Read this:

Array Aggregator – mapping multiple bundles into a complex field

The Array Aggregator module is very powerful because it allows you to build a complex array of collections for a later module’s field to map multiple items (collections) to it.

This is done using the “Target structure type” of an Array Aggregator module.

Here is an example:

As you can see, the “Map” toggle on complex fields are used when you have an array. You can easily build an array variable to map to a future module’s field, by using an Array Aggregator module and select the “Target Structure Type” as the future module’s field you have mapped the array into.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like