Few months ago I succeeded with your help to make my 1st automation
while it is far from perfect, it was fine because it was for a POC and I was able to do the rest with sed and in a spreasheet.
Now I would fully like to automate it fuly but my JS knowledge is 0; ok maybe 1 because I figure I should use this String.prototype.replace() - JavaScript | MDN
here a sample of my data
{
"secteur": "Sylviculture et exploitation forestière",
"url": "/liste-69-02.html",
"nombre d'entreprises": "(1368)",
},
I would like to
- remove the ( and ) in the item
"nombre d'entreprises": "(1368)",
- add https://website.com/ before /liste-*.html in the item
"url": "/liste-69-02.html",
Remark: inside ( ) it is always a number between 0 and …
So who want to be my hero ?
Thank you in advance.
Hey @JOduMonT, hope you are well?
I think the link you have posted is a pretty great start for the transformation you have in mind. You can actually use JavaScript inside n8n expressions, so they’d be a great way of using the .replace()
method from your link. To remove a single opening bracket (
, you can append something like .replace("(", "")
to your expression. This replaces the bracket with an empty string, so essentially removes it. Repeat for the closing bracket )
and we’ve successfully removed all unwanted brackets.
Adding a text before an existing value would not need Javascript at all, you could instead simply put https://website.com/
in front of your expression, like so: https://website.com/{{$json["url"]}}
.
Here’s a quick example workflow showing all of this combined in a single Set node. You can simply copy it straight into your n8n canvas:
Example Workflow
Hope this helps! Give me a shout if you have any questions on this