I have a JSON object that contains an array that’s being returned from an API, and I want to extract only the domain element… what’s the best way to go about it.
[
{
"status_code": 200,
"error": null,
"response": {
"scandata_raw": [
{
"datasource": "scan",
"domain": "domain1.com",
"scan_date": "2024-09-10 08:23:48"
},
{
"datasource": "scan",
"domain": "domain2.net",
"scan_date": "2024-09-10 08:23:19"
},
{
"datasource": "scan",
"domain": "domain3.org",
"scan_date": "2024-09-10 08:21:06"
}
]
}
}
]
I’ve been trying to use a code node to parse out my data, but I don’t know how to access all indices of the array…
Using
return {
json: {
domains: $input.all().map(item => item.json.response.scandata_raw)
}
}
The data gets passed through virtually unchanged.
If I use
return {
json: {
domains: $input.all().map(item => item.json.response.scandata_raw[0])
}
}
I only get the domain at index 0
If I use
return {
json: {
domains: $input.all().map(item => item.json.response.scandata_raw.domain)
}
}
I get no output.
- n8n version: 1.56.2
- Database (default: SQLite): Default
- n8n EXECUTIONS_PROCESS setting (default: own, main): ?
- Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
- Operating system: macOS