Hi,
Trying to mix this Break multiple values in JSON with this Splitting an array to extract values
I got in a JSON:
[
{
“site”:“https://www.domain1.com/ ”,
}
{
“site”:“https://domain2.com/ ”,
}
{
“site”:“http://www.1.domain.com/ ”,
}
]
How to get to:
[
{
“site”:“domain1.com ”,
}
{
“site”:“domain2.com ”,
}
{
“site”:“1.domain.com ”,
}
]
I assume I need some iterations? To get rid of "http(s) prefix and the “www” and “/” but so far I could only get specific defined strings out of it. Thank you very much once again . Have a great weekend.
The example below should do it.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n domain: 'https://www.domain1.com/',\n }\n },\n {\n json: {\n domain: 'https://www.domain2.com/',\n }\n },\n {\n json: {\n domain: 'https://www.domain3.com/',\n }\n }\n]"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
460,
300
]
},
{
"parameters": {
"functionCode": "\nconst matches = item.domain.match(/^https?\\:\\/\\/([^\\/?#]+)(?:[\\/?#]|$)/i);\n // extract hostname (will be null if no match is found)\nitem._domain = matches && matches[1];\n\nitem._domain = item._domain.replace('www.', '');\nreturn item"
},
"name": "FunctionItem",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
700,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "FunctionItem",
"type": "main",
"index": 0
}
]
]
}
}
}
1 Like
RicardoE105:
Wow, jeez guys, you are the best, fast and this worked perfect once more .
Thanks a mil
1 Like