2023-02-09 04:56:39 -08:00
{
"nodes" : [
{
"parameters" : { } ,
2023-05-30 03:56:55 -07:00
"id" : "33eede8d-2ab0-42ab-b79a-a069d8549ab0" ,
2023-02-09 04:56:39 -08:00
"name" : "When clicking \"Execute Workflow\"" ,
"type" : "n8n-nodes-base.manualTrigger" ,
"typeVersion" : 1 ,
2023-05-30 03:56:55 -07:00
"position" : [ -40 , 580 ]
2023-02-09 04:56:39 -08:00
} ,
{
"parameters" : {
"jsCode" : "return[\n { value: 1 },\n { value: 2 },\n]"
} ,
2023-05-30 03:56:55 -07:00
"id" : "a5913b52-24dc-4f81-bb7f-f90e61dad978" ,
2023-02-09 04:56:39 -08:00
"name" : "Sample Data" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
2023-05-30 03:56:55 -07:00
"position" : [ 200 , 580 ]
2023-02-09 04:56:39 -08:00
} ,
{
"parameters" : {
"jsCode" : "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nlet sum = 0;\nfor (const item of $input.all()) {\n sum += item.json.value;\n}\n\nreturn [ {sum} ];"
} ,
2023-05-30 03:56:55 -07:00
"id" : "c4ad4913-5af3-42bc-a784-69182f1facdd" ,
2023-02-09 04:56:39 -08:00
"name" : "Run Once for All Items" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
2023-05-30 03:56:55 -07:00
"position" : [ 460 , 320 ]
} ,
{
"parameters" : {
"jsCode" : "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nlet sum = 0;\nfor (const item of items) {\n sum += item.json.value;\n}\n\nreturn [ {sum} ];"
} ,
"id" : "34cbd204-4335-4790-92cd-c3df617eee21" ,
"name" : "Run Once for All Items (Legacy Syntax)" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
"position" : [ 460 , 500 ]
2023-02-09 04:56:39 -08:00
} ,
{
"parameters" : {
"mode" : "runOnceForEachItem" ,
"jsCode" : "// Add a new field called 'myNewField' to the\n// JSON of the item\n$input.item.json.myNewField = $input.item.json.value;\n\nreturn $input.item;"
} ,
2023-05-30 03:56:55 -07:00
"id" : "f67d29bf-554a-4572-8867-4456182dec24" ,
2023-02-09 04:56:39 -08:00
"name" : "Run Once for Each Item" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
2023-05-30 03:56:55 -07:00
"position" : [ 460 , 680 ]
} ,
{
"parameters" : {
"mode" : "runOnceForEachItem" ,
"jsCode" : "// Add a new field called 'myNewField' to the\n// JSON of the item\nitem.json.myNewField = item.json.value;\n\nreturn item;"
} ,
"id" : "6f4bf149-e84e-4e0d-802a-7eaf7a42b18c" ,
"name" : "Run Once for Each Item (Legacy Syntax)" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
"position" : [ 460 , 860 ]
2024-08-06 06:16:33 -07:00
} ,
{
"parameters" : {
"mode" : "runOnceForEachItem" ,
"jsCode" : "const json = $input.item.json\njson.myNewField = await (async () => json.value)();\n\nreturn $input.item;"
} ,
"id" : "3cff4a64-c3fd-47d3-a33e-3c446846138f" ,
"name" : "With Async Functions" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
"position" : [
460 ,
1200
]
} ,
{
"parameters" : {
"mode" : "runOnceForEachItem" ,
"jsCode" : "const json = $input.item.json\njson.myNewField = await new Promise((resolve) => resolve(json.value));\n\nreturn $input.item;"
} ,
"id" : "947e4e3e-2da3-40c5-97da-830c4572fc05" ,
"name" : "With Promises" ,
"type" : "n8n-nodes-base.code" ,
"typeVersion" : 1 ,
"position" : [
460 ,
1380
]
2023-02-09 04:56:39 -08:00
}
] ,
"pinData" : {
"Run Once for All Items" : [
{
"json" : {
"sum" : 3
}
}
] ,
"Run Once for Each Item" : [
{
"json" : {
"value" : 1 ,
"myNewField" : 1
}
} ,
{
"json" : {
"value" : 2 ,
"myNewField" : 2
}
}
2023-05-30 03:56:55 -07:00
] ,
"Run Once for All Items (Legacy Syntax)" : [
{
"json" : {
"sum" : 3
}
}
] ,
"Run Once for Each Item (Legacy Syntax)" : [
{
"json" : {
"value" : 1 ,
"myNewField" : 1
}
} ,
{
"json" : {
"value" : 2 ,
"myNewField" : 2
}
}
2024-08-06 06:16:33 -07:00
] ,
"With Async Functions" : [
{
"json" : {
"value" : 1 ,
"myNewField" : 1
}
} ,
{
"json" : {
"value" : 2 ,
"myNewField" : 2
}
}
] ,
"With Promises" : [
{
"json" : {
"value" : 1 ,
"myNewField" : 1
}
} ,
{
"json" : {
"value" : 2 ,
"myNewField" : 2
}
}
2023-02-09 04:56:39 -08:00
]
} ,
"connections" : {
"When clicking \"Execute Workflow\"" : {
"main" : [
[
{
"node" : "Sample Data" ,
"type" : "main" ,
"index" : 0
}
]
]
} ,
"Sample Data" : {
"main" : [
[
{
"node" : "Run Once for All Items" ,
"type" : "main" ,
"index" : 0
} ,
{
"node" : "Run Once for Each Item" ,
"type" : "main" ,
"index" : 0
2023-05-30 03:56:55 -07:00
} ,
{
"node" : "Run Once for All Items (Legacy Syntax)" ,
"type" : "main" ,
"index" : 0
} ,
{
"node" : "Run Once for Each Item (Legacy Syntax)" ,
"type" : "main" ,
"index" : 0
2024-08-06 06:16:33 -07:00
} ,
{
"node" : "With Async Functions" ,
"type" : "main" ,
"index" : 0
} ,
{
"node" : "With Promises" ,
"type" : "main" ,
"index" : 0
2023-02-09 04:56:39 -08:00
}
]
]
}
2023-05-30 03:56:55 -07:00
}
}