I need some help modifying json data as part of a larger csv edit workflow. In this step, I’m trying to split (or at the very least limit) the URLs in the ‘PHOTO URL’ field at 5 and push the remaining into an overflow field.
I tried using a Set node with an expression using .slice() but it ended up just slicing the value itself, not treating each item inside the value as an item to slice. (not even sure if i’m wording this right because js is not my forté).
In my current workflow, the JSON data looks like this:
[
{
"NAME": 31057,
"PHOTO URL": "https://url.one; https://url.two; https://url.three; https://url.four; https://url.five; https://url.six; https://url.seven; https://url.eight; https://url.nine; https://url.ten;"
},
{
"NAME": 32000,
"PHOTO URL": "https://url.one; https://url.two; https://url.three; https://url.four; https://url.five; https://url.six; https://url.seven; https://url.eight; https://url.nine; https://url.ten;"
},
]
The goal is for the data to look like this:
[
{
"NAME": 31057,
"PHOTO URL": "https://url.one; https://url.two; https://url.three; https://url.four; https://url.five",
"photo-overflow": "https://url.six; https://url.seven; https://url.eight; https://url.nine; https://url.ten;"
},
{
"NAME": 32000,
"PHOTO URL": "https://url.one; https://url.two; https://url.three; https://url.four; https://url.five",
"photo-overflow": "https://url.six; https://url.seven; https://url.eight; https://url.nine; https://url.ten;"
},
]
Any help is appreciated!
Edited with the solution i implemented with the help of @BramKn
What my nodes ended up looking like was below:
I used a Set node first with the expression:
{{json["PHOTO URL"].split("; ").slice(0,5).join("; ")}}
followed by a function item node
const overflowUrl = $node["original-csv"].json["PHOTO URL"].split("; ").slice(5).join("; ")}};
item.overflowPhoto = overflowUrl;
return item;
- n8n version: 0.169.0
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm