Extracting Fields While Creating An Array From Bundles

If I iterate over an array - which gives me a list of bundles - is it possible to extract specific nested fields from those bundles, while aggregating them back into an array?

E.g. my bundles are:

[
    {
        "object": "page",
        "id": "1061063e-a445-477d-be42-2f1b7a3004db",
        "created_time": "2024-01-10T14:45:00.000Z",
        "last_edited_time": "2024-01-10T14:48:00.000Z",
        "created_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "last_edited_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "cover": null,
        "icon": null,
        "parent": {
            "type": "database_id",
            "database_id": "6f3dc480-b056-4532-b634-c5f81316e611"
        },
        "archived": false,
        "properties": {
            "Email": {
                "id": "YlqD",
                "type": "email",
                "email": "person1@example.com"
            },
            "Name": {
                "id": "title",
                "type": "title",
                "title": [
                    {
                        "type": "text",
                        "text": {
                            "content": "Person 1",
                            "link": null
                        },
                        "annotations": {
                            "bold": false,
                            "italic": false,
                            "strikethrough": false,
                            "underline": false,
                            "code": false,
                            "color": "default"
                        },
                        "plain_text": "Person 1",
                        "href": null
                    }
                ]
            }
        },
        "url": "https://www.notion.so/Person-1-1061063ea445477dbe422f1b7a3004db",
        "public_url": null,
        "__IMTINDEX__": 1,
        "__IMTLENGTH__": 3
    },
    {
        "object": "page",
        "id": "4936d51f-7a18-4526-b638-6bdc3fcdd741",
        "created_time": "2024-01-10T14:45:00.000Z",
        "last_edited_time": "2024-01-10T14:48:00.000Z",
        "created_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "last_edited_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "cover": null,
        "icon": null,
        "parent": {
            "type": "database_id",
            "database_id": "6f3dc480-b056-4532-b634-c5f81316e611"
        },
        "archived": false,
        "properties": {
            "Email": {
                "id": "YlqD",
                "type": "email",
                "email": "person3@example.com"
            },
            "Name": {
                "id": "title",
                "type": "title",
                "title": [
                    {
                        "type": "text",
                        "text": {
                            "content": "Person 3",
                            "link": null
                        },
                        "annotations": {
                            "bold": false,
                            "italic": false,
                            "strikethrough": false,
                            "underline": false,
                            "code": false,
                            "color": "default"
                        },
                        "plain_text": "Person 3",
                        "href": null
                    }
                ]
            }
        },
        "url": "https://www.notion.so/Person-3-4936d51f7a184526b6386bdc3fcdd741",
        "public_url": null,
        "__IMTINDEX__": 2,
        "__IMTLENGTH__": 3
    },
    {
        "object": "page",
        "id": "ab9ffec9-ead9-4b30-9071-735f20243442",
        "created_time": "2024-01-10T14:45:00.000Z",
        "last_edited_time": "2024-01-10T14:48:00.000Z",
        "created_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "last_edited_by": {
            "object": "user",
            "id": "7a0fb8cf-d3c5-452d-b159-446a826bae3d"
        },
        "cover": null,
        "icon": null,
        "parent": {
            "type": "database_id",
            "database_id": "6f3dc480-b056-4532-b634-c5f81316e611"
        },
        "archived": false,
        "properties": {
            "Email": {
                "id": "YlqD",
                "type": "email",
                "email": "person2@example.com"
            },
            "Name": {
                "id": "title",
                "type": "title",
                "title": [
                    {
                        "type": "text",
                        "text": {
                            "content": "Person 2",
                            "link": null
                        },
                        "annotations": {
                            "bold": false,
                            "italic": false,
                            "strikethrough": false,
                            "underline": false,
                            "code": false,
                            "color": "default"
                        },
                        "plain_text": "Person 2",
                        "href": null
                    }
                ]
            }
        },
        "url": "https://www.notion.so/Person-2-ab9ffec9ead94b309071735f20243442",
        "public_url": null,
        "__IMTINDEX__": 3,
        "__IMTLENGTH__": 3
    }
]

And I want to extract the id and properties.Email.email from each bundle, to create an array that I can extract values from using the map() function.

I know I can put a Set Multiple Variables step between the Iterator and the Array Aggregator modules to extract those fields. But then I’m using an operation per bundle and that’s what I’m trying to avoid here.

This is the output that I’m looking for but without using the Set Multiple Variables step.

I’ve figured out that I can access the email addresses with {{map(5.body.results; "properties.Email.email")}} in a Set Variable step. But I need to create an array where each item is an collection containing the id and email fields.

Ok so toCollection() + toArray() will do the job for me here -

{{toArray(toCollection(5.body.results; "id"; "properties.Email.email"))}}

Gives me:

[
    {
        "Contacts": [
            {
                "key": "1061063e-a445-477d-be42-2f1b7a3004db",
                "value": "person1@example.com"
            },
            {
                "key": "4936d51f-7a18-4526-b638-6bdc3fcdd741",
                "value": "person3@example.com"
            },
            {
                "key": "ab9ffec9-ead9-4b30-9071-735f20243442",
                "value": "person2@example.com"
            }
        ]
    }
]

But I’d still like to know whether it’s possible to extract additional fields as values, alongside the email address…

Hey @alexs
Welcome to the Make Community

Use Text Aggregator to make it in JSON Format with Comma as Row Separator

Use Parse JSON Module to make array of JSON

Use Array Aggregator that you want to use

Here you will get the data in array

Blueprint of this scenario attached
blueprint (6).json (11.4 KB)

Thanks,
Sachin Shrivastava

2 Likes

Ah that’s what I was looking for, although I only needed the first two steps, thank you!

3 Likes

Just thought I’d post the text JSON for the Parse JSON step, to make it easy to copy and paste, as I keep coming back to this thread -

{"data":[{"field1":"","field1":""}]}

2 Likes