Text Parser bundles to JSON object

Hi everyone,

I am using a Text Parser module to extract some URL parameters from an email message. This seems to be working ok and the module outputs the following data:

Now I am trying to figure out how I can take the data from these different bundles and put it into one JSON object. I have been trying to use the “Aggregate to JSON” module but I don’t really understand how it works (I am also not great with JSON).

Could anyone help me to understand how to accomplish this?

Thank you very much :pray: :pray:

Welcome to the Make community!

Looks like you are using the Match Pattern (advanced) module, which may not be suitable.

Also if you turn on “Global Match” it will output multiple bundles.

Could you switch to using the non-advanced version, and share your example text input and pattern?

If you need 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:

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.


(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, Input/Output bundles

Please provide the input and output bundles of the trigger/iterator/aggregator modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.

A.

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

Uploading them here will look like this:

module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles 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:

Providing the input/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!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Hi, thanks for your reply. I am not using the advanced module. My pattern is:

utm_source=([^&\s]+)|utm_medium=([^&\s]+)|utm_id=([^&\s]+)|utm_campaign=([^&\s]+)|utm_term=([^&\s]+)

And the example text in this case:

image

Correct me if I am wrong but I understand that it is normal for this module to output several bundles since I am using it to extract several parameters at the same time? If that is the case, I just need to find a way to combine the bundles.

I tried using an Array Aggregator but not sure if it is working correctly.

Can you please paste the example text here instead of a screenshot?

When reaching out for assistance with your regex pattern for a Text Parser module, it would be super helpful if you could share the actual text you’re trying to match. Screenshots of text can be a bit tricky, so if you could copy and paste the text directly here, that would be awesome! It ensures we can run it against test patterns effectively. If there’s any sensitive info, feel free to change it to something fictional yet still valid by keeping the format intact.

Providing clear text examples saves time on both ends and helps us give you the best possible solution. Without proper examples, we might end up playing a guessing game, and nobody wants that as it is a waste of time! You are more likely to get a correct answer faster. So, help us help you by sharing those text snippets. Thanks a bunch!

1 Like

Sure, please see below:

Page URL: fbclid=IwAR00ck-uGZYHoQoHuurZvYy3lIndx0GISIMav6Zyedgnhr88u-0RQtRkUPw_aem_pjooQqe7W8K54MDQ5Kri-g&utm_medium=paid&utm_source=fb&utm_id=6473927987887

Sorry, just figured out how to post the output bundles from the Text Parsing module:

[
    {
        "i": 1,
        "$2": "paid"
    },
    {
        "i": 2,
        "$1": "fb"
    },
    {
        "i": 3,
        "$3": "6473927987887"
    },
    {
        "i": 4,
        "$5": "6473936854287"
    },
    {
        "i": 5,
        "$4": "6473927987887"
    }
]

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of three modules if you want them in their own variables:

1. Text Parser

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

[?&](?<key>[^=]+)=(?<value>[^&]*)

Proof

https://regex101.com/r/sLGXcC

Important Info

  • :warning: Global match must be set to YES!

Screenshot

Screenshot_2024-06-25_180651

Output

Screenshot_2024-06-25_180623


For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

2. Array Aggregator

Aggregate the key, value matches

Screenshot_2024-06-25_180614

3. (optional) Convert to collection

Screenshot_2024-06-25_180648

Output

Screenshot_2024-06-25_180632

Hope this helps!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

2 Likes

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": 191,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "[?&](?<key>[^=]+)=(?<value>[^& ]*)",
                        "global": true,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false,
                        "ignoreInfiniteLoopsWhenGlobal": false
                    },
                    "mapper": {
                        "text": "Page URL: https://example.com/?fbclid=IwAR00ck-uGZYHoQoHuurZvYy3lIndx0GISIMav6Zyedgnhr88u-0RQtRkUPw_aem_pjooQqe7W8K54MDQ5Kri-g&utm_medium=paid&utm_source=fb&utm_id=6473927987887"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2323,
                            "y": -2254
                        },
                        "restore": {},
                        "parameters": [
                            {
                                "name": "pattern",
                                "type": "text",
                                "label": "Pattern",
                                "required": true
                            },
                            {
                                "name": "global",
                                "type": "boolean",
                                "label": "Global match",
                                "required": true
                            },
                            {
                                "name": "sensitive",
                                "type": "boolean",
                                "label": "Case sensitive",
                                "required": true
                            },
                            {
                                "name": "multiline",
                                "type": "boolean",
                                "label": "Multiline",
                                "required": true
                            },
                            {
                                "name": "singleline",
                                "type": "boolean",
                                "label": "Singleline",
                                "required": true
                            },
                            {
                                "name": "continueWhenNoRes",
                                "type": "boolean",
                                "label": "Continue the execution of the route even if the module finds no matches",
                                "required": true
                            },
                            {
                                "name": "ignoreInfiniteLoopsWhenGlobal",
                                "type": "boolean",
                                "label": "Ignore errors when there is an infinite search loop",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "key",
                                "label": "key"
                            },
                            {
                                "type": "text",
                                "name": "value",
                                "label": "value"
                            },
                            {
                                "type": "uinteger",
                                "name": "i",
                                "label": "i"
                            },
                            {
                                "type": "any",
                                "name": "__IMTMATCH__",
                                "label": "Fallback Match"
                            }
                        ]
                    }
                },
                {
                    "id": 194,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 191
                    },
                    "mapper": {
                        "key": "{{191.key}}",
                        "value": "{{191.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -2078,
                            "y": -2255
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Text parser - Match pattern [191]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        }
                    }
                },
                {
                    "id": 195,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "params",
                        "scope": "roundtrip",
                        "value": "{{toCollection(194.array; \"key\"; \"value\")}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -1836,
                            "y": -2258
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "params",
                                "label": "params",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

This is great, thank you so much! I will try this out now :grinning:

Just one more question about the REGEX. In my example text input there was not a problem, but what if my text input occasionally looks something like this:

My text starts here and has some & characters in it but they are not part of the parameters.


Date: June 20, 2024
Time: 7:36 am
Page URL: https://kat-tech.co.th/?fbclid=IwAR00ck-uGZYHoQoHuurZvYy3lIndx0GISIMav6Zyedgnhr88u-0RQtRkUPw_aem_pjooQqe7W8K54MDQ5Kri-g&utm_medium=paid&utm_source=fb&utm_id=6473927987887&utm_content=6477661044287&utm_term=6473936854287&utm_campaign=6473927987887

And then my text continues here, and this is also not part of the parameters.

Is there a way to make sure that I only get the parameters if the text looks like in my example above?

If the text below doesn’t contain any URL, then you’re fine.

But that is a question for another thread.

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Ok, thank you very much for your help! Everything works perfect! :grinning:

1 Like

No problem, glad I could help, and thank you for providing the requested example bundles and text.

1. If anyone has 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!

4. Do join the unofficial Make Discord server for live chat and video assistance

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like