Converting collection in array into plain text

Dear all,

I have this collection as part of an array.

“Nutritional value”: {
“Carbohydrates”: “35 g”,
“Protein”: “24 g”,
“Total Fat”: “12 g”,
“Saturated Fat”: “4 g”,
“Trans Fat”: “0 g”,
“Monounsaturated Fat”: “5 g”,
“Polyunsaturated Fat”: “2 g”,
“Cholesterol”: “90 mg”,
“Sodium”: “950 mg”,
“Dietary Fiber”: “2 g”,
“Sugar”: “12 g”,
“Calcium”: “40 mg”,
“Potassium”: “399 mg”,
“Iron”: “2.1 mg”,
“Vitamin A”: “35 µg”,
“Vitamin C”: “1 mg”
},

I have been searching the entire forum for solution to converting this collection into a plain text, but can’t find it.

It should just simply convert into something like this below, which I can reuse in a Chatgpt prompt or some other module downstream.

Per Serving in Calories: 350 kcal
Carbohydrates: 35 g
etc. etc

Appreciate any kind of help

You can use the module Tools > “Compose a string”, and you can map the variables into there in the format that you want.

2 Likes

thanks so much for the quick reply.

The only problem is…
I don’t know what these components will be as I am getting it from GPT, so sometimes it’s more, and sometimes it’s less… hence It’s important that the varaibles and the keys are all just output from the array… Appreciate your help.

In that case you’ll need a minimum of two modules:

Screenshot_2024-04-16_160413

 {{114.key}}: {{114.value.value}}

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

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

  1. Copy the 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 to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 114,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{toArray(112.`Nutritional value`)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -569,
                            "y": -2983
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 115,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "rowSeparator": "\n",
                        "feeder": 114
                    },
                    "mapper": {
                        "value": " {{114.key}}: {{114.value.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -323,
                            "y": -2983,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "rowSeparator": {
                                    "label": "New row"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Iterator [114]"
                                }
                            },
                            "flags": {
                                "groupBy": {
                                    "collapsed": true
                                },
                                "stopIfEmpty": {
                                    "collapsed": true
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
3 Likes

It worked :slight_smile: Thank you so much.

2 Likes

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!

Links

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

3 Likes