Hi again,
I loaded up your full object into a Parse JSON module and realized that the paragraph collection needs no function to access it – you simply reference it as follows
{{1.paragraph}}
Since there are no arrays and it’s just a set of nested collections the paragraph collection is at the top level of the bundle.
But your question is really more about iterating the results array coming out of an HTTP request so it’s a bit more complex than that.
Since you’re forming a new piece of JSON text, I use the Transform to JSON module to convert your heading_2 and paragraph collections into JSON text in the iterator loop. Then in the aggregator I grab the relevant object based on the bundle order position. The text aggregator expects text to aggregate so you cannot reference the objects there or you’ll just get {object} or {collection} as the output and you need actual text to place into your resulting new structure. Then I do a final Parse JSON so you can confirm indeed you are getting the results you need.
blueprint (39).json (23.9 KB)
But you can also do this without iterators or any of the other modules in just 1 set multiple variables module:
to get heading_2 you do
{{remove(map(6.body.results; "heading_2"); null)}}
to get paragraph(s) you do
{{remove(map(6.body.results; "paragraph"); null)}}
The remove call removes the empty collections generated as a result of the map to the results array which has 3 elements in it and the map for heading_2 generates 2 empty collections, while paragraph generates 1 empty collection since there are 2 paragraph collections in the array.
You can even merge these into one set of collections with the merge() function
{{merge(remove(map(6.body.results; "heading_2"); null); remove(map(6.body.results; "paragraph"); null))}}
copy and paste this blueprint using map() into a new scenario
{
"subflows": [
{
"flow": [
{
"id": 6,
"module": "json:ParseJSON",
"version": 1,
"parameters": {
"type": ""
},
"mapper": {
"json": "[\n {\n \"body\": {\n \"object\": \"list\",\n \"results\": [\n {\n \"object\": \"block\",\n \"id\": \"0825bcb9-af91-4a0d-bacb-9121a8134aa3\",\n \"parent\": {\n \"type\": \"page_id\",\n \"page_id\": \"5488ff58-8374-4f31-8b89-4b470461f897\"\n },\n \"created_time\": \"2024-06-07T10:12:00.000Z\",\n \"last_edited_time\": \"2024-06-07T10:12:00.000Z\",\n \"created_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"last_edited_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"has_children\": false,\n \"archived\": false,\n \"in_trash\": false,\n \"type\": \"heading_2\",\n \"heading_2\": {\n \"rich_text\": [\n {\n \"type\": \"text\",\n \"text\": {\n \"content\": \"A Heading\",\n \"link\": null\n },\n \"annotations\": {\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"code\": false,\n \"color\": \"default\"\n },\n \"plain_text\": \"A Heading\",\n \"href\": null\n }\n ],\n \"is_toggleable\": false,\n \"color\": \"default\"\n }\n },\n {\n \"object\": \"block\",\n \"id\": \"9abed4e9-7e71-499e-8e65-485460bf213a\",\n \"parent\": {\n \"type\": \"page_id\",\n \"page_id\": \"5488ff58-8374-4f31-8b89-4b470461f897\"\n },\n \"created_time\": \"2024-06-07T10:12:00.000Z\",\n \"last_edited_time\": \"2024-06-07T10:12:00.000Z\",\n \"created_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"last_edited_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"has_children\": false,\n \"archived\": false,\n \"in_trash\": false,\n \"type\": \"paragraph\",\n \"paragraph\": {\n \"rich_text\": [\n {\n \"type\": \"text\",\n \"text\": {\n \"content\": \"Some text.\",\n \"link\": null\n },\n \"annotations\": {\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"code\": false,\n \"color\": \"default\"\n },\n \"plain_text\": \"Some text.\",\n \"href\": null\n }\n ],\n \"color\": \"default\"\n }\n },\n {\n \"object\": \"block\",\n \"id\": \"c25888a9-281b-4355-b370-b43d13fa4fee\",\n \"parent\": {\n \"type\": \"page_id\",\n \"page_id\": \"5488ff58-8374-4f31-8b89-4b470461f897\"\n },\n \"created_time\": \"2024-06-07T10:12:00.000Z\",\n \"last_edited_time\": \"2024-06-07T10:13:00.000Z\",\n \"created_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"last_edited_by\": {\n \"object\": \"user\",\n \"id\": \"7a0fb8cf-d3c5-452d-b159-446a826bae3d\"\n },\n \"has_children\": false,\n \"archived\": false,\n \"in_trash\": false,\n \"type\": \"paragraph\",\n \"paragraph\": {\n \"rich_text\": [\n {\n \"type\": \"text\",\n \"text\": {\n \"content\": \"Some more text.\",\n \"link\": null\n },\n \"annotations\": {\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"code\": false,\n \"color\": \"default\"\n },\n \"plain_text\": \"Some more text.\",\n \"href\": null\n }\n ],\n \"color\": \"default\"\n }\n }\n ],\n \"next_cursor\": null,\n \"has_more\": false,\n \"type\": \"block\",\n \"block\": {},\n \"request_id\": \"478c8e1d-4b8c-4c38-a2ae-4a6373796805\"\n },\n \"headers\": {\n \"date\": \"Fri, 07 Jun 2024 10:13:23 GMT\",\n \"content-type\": \"application/json; charset=utf-8\",\n \"transfer-encoding\": \"chunked\",\n \"connection\": \"close\",\n \"x-powered-by\": \"Express\",\n \"x-notion-request-id\": \"478c8e1d-4b8c-4c38-a2ae-4a6373796805\",\n \"etag\": \"W/\\\"90e-faeK4/3nYw0G1YL7nKnhLeqmwEM\\\"\",\n \"vary\": \"Accept-Encoding\",\n \"cf-cache-status\": \"DYNAMIC\",\n \"set-cookie\": [\n \"__cf_bm=qezvWFcp5sErSCpQVqmaJsQ.q.00qE_94aeyt1GsbV8-1717755203-1.0.1.1-5ck9n4rVMRAa6XXcef0zMl8VRE6GOcXMrlOHhL6RM5UWvbw0pxSErwn8Bu9Bxs61uJNAxG6.gXVyAjONR2IveA; path=/; expires=Fri, 07-Jun-24 10:43:23 GMT; domain=.notion.com; HttpOnly; Secure; SameSite=None\"\n ],\n \"server\": \"cloudflare\",\n \"cf-ray\": \"88ffde869fd59573-DUB\"\n },\n \"statusCode\": 200\n }\n]"
},
"metadata": {
"designer": {
"x": 0,
"y": 150
},
"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": 10,
"module": "builtin:BasicRouter",
"version": 1,
"mapper": null,
"metadata": {
"designer": {
"x": 300,
"y": 150
}
},
"routes": [
{
"flow": [
{
"id": 11,
"module": "util:SetVariables",
"version": 1,
"parameters": {},
"mapper": {
"variables": [
{
"name": "heading_2",
"value": "{{remove(map(6.body.results; \"heading_2\"); null)}}"
},
{
"name": "paragraph",
"value": "{{remove(map(6.body.results; \"paragraph\"); null)}}"
}
],
"scope": "roundtrip"
},
"metadata": {
"designer": {
"x": 600,
"y": 300
},
"restore": {
"expect": {
"variables": {
"items": [
null,
null
]
},
"scope": {
"label": "One cycle"
}
}
},
"expect": [
{
"name": "variables",
"type": "array",
"label": "Variables",
"spec": [
{
"name": "name",
"label": "Variable name",
"type": "text",
"required": true
},
{
"name": "value",
"label": "Variable value",
"type": "any"
}
]
},
{
"name": "scope",
"type": "select",
"label": "Variable lifetime",
"required": true,
"validate": {
"enum": [
"roundtrip",
"execution"
]
}
}
],
"interface": [
{
"name": "heading_2",
"label": "heading_2",
"type": "any"
},
{
"name": "paragraph",
"label": "paragraph",
"type": "any"
}
]
}
}
]
}
]
}
]
}
],
"metadata": {
"version": 1
}
}
Check out my series of videos and scenario walkthroughs for Make Newbies
These scenario walkthroughs can be very useful for people new to Make and need a quick set of exercises to manipulate data structures.
–
Alex Sirota
Director of NewPath Consulting - we are Make Heroes!
Check out my series of videos and scenario walkthroughs for Make Newbies