Filtering array items based on how often a value occurs

Sup there guys, so i’m trying to loop through the array of JSON objects (shown below) and basically I want to do two things:

  • Aggregate how many the same ‘profileLink’ occurs in the list
  • Filter out all the items where the profileLink occurs less then 3 times

Current flow

The main goal here is that I want to get back a list of profiles who have frequently engaged with our content, so I can add these people to a Spreadsheet to reach out too

I know how i’d do this in code, but a little confused how this works on Make :thinking:

Appreciate it!

Welcome to the Make community!

To “combine” them into a single structure, 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.

Once you have aggregated the bundles, you can use the built-in function count to get the number of items in the array

e.g.:

{{ count(array) }}

For more information, see

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

Partner & Custom Apps

samliewrequest private consultation

Join the Make unofficial Discord server!

1 Like

Appreciate the prompt response man!

How do I count up how many times the same profileLink occurs in the array?

In my head I’d want a structure like:

{
  "httpa://linkedIn.com/1": 2,
  "httpa://linkedIn.com/3": 4,
  "httpa://linkedIn.com/7": 8,
  "httpa://linkedIn.com/2": 1
}

Then I’d want to filter out all the urls that appear less then twice e.g.

For further assistance, please provide the following:

1. Screenshots of module fields and filters

Please share screenshots of relevant module fields and filters in question? It would really help other community members to see what you’re looking at.

You can upload images here using the Upload icon in the text editor:
Screenshot_2023-10-07_111039

2. Scenario blueprint

Please export the scenario blueprint file to allow others to view the mappings and settings. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826
(Note: Exporting your scenario will not include private information or keys to your connections)

Uploading it here will look like this:

blueprint.json (12.3 KB)

3. And most importantly, Output bundles

Please provide the output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

A.

Save the bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading it here will look like this:

bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

1 Like

Attached my blueprint and bundle below brother:

blueprint.json (12.0 KB)

bundle.txt (518.2 KB)

Yes, that is possible. You’ll need a minimum of two modules:

1. Aggregate bundles, group by profileLink

2. Filter at least 3 in array

3. Aggregate to text

Give it a go and let us know if you have any issues!

Output

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 6,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[]"
                    },
                    "metadata": {
                        "designer": {
                            "x": 605,
                            "y": 2
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 9,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 6
                    },
                    "mapper": {
                        "job": "{{6.job}}",
                        "name": "{{6.name}}",
                        "degree": "{{6.degree}}",
                        "postUrl": "{{6.postUrl}}",
                        "lastName": "{{6.lastName}}",
                        "firstName": "{{6.firstName}}",
                        "timestamp": "{{6.timestamp}}",
                        "companyUrl": "{{6.companyUrl}}",
                        "companyName": "{{6.companyName}}",
                        "profileLink": "{{6.profileLink}}",
                        "reactionType": "{{6.reactionType}}",
                        "followersCount": "{{6.followersCount}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 848,
                            "y": 1
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "JSON - Parse JSON [6]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        },
                        "advanced": true
                    },
                    "flags": {
                        "groupBy": "{{6.profileLink}}",
                        "stopIfEmpty": true
                    }
                },
                {
                    "id": 12,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 9,
                        "rowSeparator": "other",
                        "otherRowSeparator": ","
                    },
                    "filter": {
                        "name": "at least three",
                        "conditions": [
                            [
                                {
                                    "a": "{{length(9.array)}}",
                                    "b": "3",
                                    "o": "number:greaterorequal"
                                },
                                {
                                    "a": "{{9.`__IMTKEY__`}}",
                                    "b": "{{emptystring}}",
                                    "o": "text:notequal"
                                }
                            ]
                        ]
                    },
                    "mapper": {
                        "value": "\"{{9.`__IMTKEY__`}}\":{{length(9.array)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 1166,
                            "y": 0,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Array aggregator [9]"
                                }
                            },
                            "parameters": {
                                "rowSeparator": {
                                    "label": "Other"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "otherRowSeparator",
                                "type": "text",
                                "label": "Separator"
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "multiline": true,
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make unofficial Discord server!

3 Likes

Amazing Sam! Thank you so much for this :pray:t5:

Is there a way somehow do this filter while still keeping the other key fields?

Now that I have a list of all the profiles that appear more then 3 times, I want to loop their bio through OpenAI

That possible?

Appreciate it brother

You literally said you wanted it in this format…

{
  "httpa://linkedIn.com/1": 2,
  "httpa://linkedIn.com/3": 4,
  "httpa://linkedIn.com/7": 8,
  "httpa://linkedIn.com/2": 1
}

Replace the text aggregator with an array aggregator.

No problem, glad I could help!

1. If you have a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

1 Like

Amazing brother, thanks

Yeah I realised just now i’d need it in another output

Will make another ticket!