Transform array

When using the Notion module “get a database item” I get the array of collections “Properties”. The format is the following:

            {
                "id": "RjtT",
                "type": "url",
                "url": "http://xyz.com/",
                "label": "Contactpage"
            },
            {
                "id": "%5CW%5DY",
                "type": "phone_number",
                "phone_number": "+123456789",
                "label": "Mobile"
            },
            {
                "id": "al%3AW",
                "type": "multi_select",
                "multi_select": [],
                "label": "Responsible"
            },
            {
                "id": "hpFU",
                "type": "last_edited_time",
                "last_edited_time": "2024-08-07T17:53:00.000Z",
                "label": "Last change at"
            },

My goal is to retrieve a simple array in the form of

{
               "Contactpage": "http://xyz.com/",
               "Mobile": "+123456789",
               "Responsible": [],
               "Last change at": "2024-08-07T17:53:00.000Z"
}

I know this is supposed to work with the map() function, but the furthest I have gotten was to retrieve a list of all categories. Is there a way to do this dynamically without hardcoding the categories?

Thanks a lot in advance!

1 Like

Yes. But first please provide the full output bundle so we can work with it.

Please provide the output bundles of the 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.

B.

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

Here are two ways to format text so that it won’t be changed by the forum:

A. Type code block manually
Add three backticks ``` before and after the content/bundle, like this:

```
content goes here
```

B. Highlight and click the format 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!

Thank you for your answer! The output (with redacted values) is the following:

[
    {
        "object": "page",
        "id": "{ID}}",
        "created_time": "2024-08-07T16:49:00.000Z",
        "last_edited_time": "2024-08-07T17:53:00.000Z",
        "created_by": {
            "object": "user",
            "id": "{ID}}"
        },
        "last_edited_by": {
            "object": "user",
            "id": "{ID}}"
        },
        "cover": null,
        "icon": null,
        "parent": {
            "type": "database_id",
            "database_id": "{ID}}"
        },
        "archived": false,
        "in_trash": false,
        "properties": [
            {
                "id": "%3E%3ESP",
                "type": "date",
                "date": null,
                "label": "Datum"
            },
            {
                "id": "%3EV%3A%60",
                "type": "people",
                "people": [
                    {
                        "object": "user",
                        "id": "{ID}}",
                        "name": "Luke Test",
                        "avatar_url": "https://redacted.com/",
                        "type": "person",
                        "person": {
                            "email": "t.test@test.com"
                        }
                    }
                ],
                "label": "Verantwortlich"
            },
            {
                "id": "D%3CrZ",
                "type": "files",
                "files": [],
                "label": "Medien / Datein"
            },
            {
                "id": "N%5C%7Cj",
                "type": "url",
                "url": null,
                "label": "Links"
            },
            {
                "id": "RjtT",
                "type": "url",
                "url": null,
                "label": "Kontaktseite"
            },
            {
                "id": "%5CW%5DY",
                "type": "phone_number",
                "phone_number": "+4912345678912",
                "label": "Telefon"
            },
            {
                "id": "al%3AW",
                "type": "multi_select",
                "multi_select": [],
                "label": "Zugehörig"
            },
            {
                "id": "hpFU",
                "type": "last_edited_time",
                "last_edited_time": "2024-08-07T17:53:00.000Z",
                "label": "Letzte Änderung um"
            },
            {
                "id": "rS%3E_",
                "type": "email",
                "email": "t.test@test.com",
                "label": "E-Mail"
            },
            {
                "id": "%7BZ%5Eh",
                "type": "status",
                "status": {
                    "id": "{ID}}",
                    "name": "In Bearbeitung",
                    "color": "blue"
                },
                "label": "Status"
            },
            {
                "id": "%7Ch%7B%7C",
                "type": "created_time",
                "created_time": "2024-08-07T16:49:00.000Z",
                "label": "Erstellt um"
            },
            {
                "id": "title",
                "type": "title",
                "title": [
                    {
                        "type": "text",
                        "text": {
                            "content": "Tim Test",
                            "link": null
                        },
                        "annotations": {
                            "bold": false,
                            "italic": false,
                            "strikethrough": false,
                            "underline": false,
                            "code": false,
                            "color": "default"
                        },
                        "plain_text": "Tim Test",
                        "href": null
                    }
                ],
                "label": "Name"
            },
            {
                "id": "{ID}}",
                "type": "checkbox",
                "checkbox": false,
                "label": "Done"
            }
        ],
        "url": "https://www.notion.so/{ID}",
        "public_url": null,
        "request_id": "{ID}}",
        "properties_value": {
            "Datum": null,
            "Verantwortlich": [
                {
                    "object": "user",
                    "id": "{ID}}",
                    "name": "Luke Test",
                    "avatar_url": "https://redacted.com/",
                    "type": "person",
                    "person": {
                        "email": "t.test@test.com"
                    }
                }
            ],
            "Medien / Datein": [],
            "Links": null,
            "Kontaktseite": null,
            "Telefon": "+4912345678912",
            "Zugehörig": [],
            "Letzte Änderung um": "2024-08-07T17:53:00.000Z",
            "E-Mail": "t.test@test.com",
            "Status": {
                "id": "b118c21f-d642-4287-9976-3c2ad635227a",
                "name": "In Bearbeitung",
                "color": "blue"
            },
            "Erstellt um": "2024-08-07T16:49:00.000Z",
            "Name": [
                {
                    "type": "text",
                    "text": {
                        "content": "Tim Test",
                        "link": null
                    },
                    "annotations": {
                        "bold": false,
                        "italic": false,
                        "strikethrough": false,
                        "underline": false,
                        "code": false,
                        "color": "default"
                    },
                    "plain_text": "Tim Test",
                    "href": null
                }
            ],
            "Done": false
        }
    }
]

The solution is probably going to be some combination of map(), flatten() and slice(), but I just can’t seem to figure out how to do it

Welcome to the Make community!

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

Example Output

Screenshot_2024-08-08_220800

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

  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.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 192,
                    "module": "json:TransformToJSON",
                    "version": 1,
                    "parameters": {
                        "space": ""
                    },
                    "mapper": {
                        "object": "{{191.properties}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2754,
                            "y": -3587,
                            "name": "Transform Properties to JSON"
                        },
                        "restore": {
                            "parameters": {
                                "space": {
                                    "label": "Empty"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "space",
                                "type": "select",
                                "label": "Indentation",
                                "validate": {
                                    "enum": [
                                        "tab",
                                        "2",
                                        "4"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "object",
                                "type": "any",
                                "label": "Object"
                            }
                        ]
                    }
                },
                {
                    "id": 193,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "{\"id\":\"[^\"]+\",\"type\":\"[^\"]+\",\"[^\"]+\":\"?(?<value>.+?)\"?,\"label\":\"(?<key>[^\"]+?)\"}",
                        "global": true,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false,
                        "ignoreInfiniteLoopsWhenGlobal": false
                    },
                    "mapper": {
                        "text": "{{192.json}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2999,
                            "y": -3587,
                            "name": "Match KVPs"
                        },
                        "restore": {
                            "parameters": {
                                "multiline": {
                                    "collapsed": true
                                },
                                "singleline": {
                                    "collapsed": true
                                },
                                "continueWhenNoRes": {
                                    "collapsed": true
                                }
                            }
                        },
                        "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": "value",
                                "label": "value"
                            },
                            {
                                "type": "text",
                                "name": "key",
                                "label": "key"
                            },
                            {
                                "type": "uinteger",
                                "name": "i",
                                "label": "i"
                            },
                            {
                                "type": "any",
                                "name": "__IMTMATCH__",
                                "label": "Fallback Match"
                            }
                        ]
                    }
                },
                {
                    "id": 194,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 193
                    },
                    "mapper": {
                        "value": "{{193.value}}",
                        "key": "{{193.key}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3243,
                            "y": -3589
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Text parser - Match pattern [193]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        }
                    }
                },
                {
                    "id": 195,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "object",
                        "scope": "roundtrip",
                        "value": "{{toCollection(194.array; \"key\"; \"value\")}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3485,
                            "y": -3592,
                            "name": "Convert to Collection"
                        },
                        "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": "object",
                                "label": "object",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

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

@samliew

2 Likes

I am extremely impressed by the extremely fast solution!! THANK YOU a ton!

1 Like