Split an Array keep sub array keys as labels

Describe the problem/error/question

I have an item that contains an array I would like to split down. Each of the array items has a unique name that represents what the contents of the array are, in this case the results of the last 30 days of my email protection report.

Using the split node on the inbound array does indeed split it down as needed, however I lose the headers in each of the arrays, which I need as labels.

Any assistance would be appreciated.

Please share your workflow

Share the output returned by the last node

Before

{
"accountId": "######",
"type": "email",
"period": "24h",
"count": "30",
"inbound": {
"allowed:none:_total": {
"2024-04-18T00:00:00+0000": 26,
"2024-04-19T00:00:00+0000": 21,
"2024-04-20T00:00:00+0000": 10,
"2024-04-21T00:00:00+0000": 8,
"2024-04-22T00:00:00+0000": 138,
"2024-04-23T00:00:00+0000": 53,
"2024-04-24T00:00:00+0000": 29,
"2024-04-25T00:00:00+0000": 40
},
"allowed:none:none": {
"2024-04-18T00:00:00+0000": 26,
"2024-04-19T00:00:00+0000": 21,
"2024-04-20T00:00:00+0000": 10,
"2024-04-21T00:00:00+0000": 8,
"2024-04-22T00:00:00+0000": 138,
"2024-04-23T00:00:00+0000": 53,
"2024-04-24T00:00:00+0000": 29,
"2024-04-25T00:00:00+0000": 40
},

After

[
{
"accountId": ""######",",
"type": "email",
"period": "24h",
"count": "30",
"outbound": {
},
"inbound": {
"2024-04-18T00:00:00+0000": 26,
"2024-04-19T00:00:00+0000": 21,
"2024-04-20T00:00:00+0000": 10,
"2024-04-21T00:00:00+0000": 8,
"2024-04-22T00:00:00+0000": 138,
"2024-04-23T00:00:00+0000": 53,
"2024-04-24T00:00:00+0000": 29,
"2024-04-25T00:00:00+0000": 40
}
},
{
"accountId": ""######",",
"type": "email",
"period": "24h",
"count": "30",
"outbound": {
},
"inbound": {
"2024-04-18T00:00:00+0000": 26,
"2024-04-19T00:00:00+0000": 21,
"2024-04-20T00:00:00+0000": 10,
"2024-04-21T00:00:00+0000": 8,
"2024-04-22T00:00:00+0000": 138,
"2024-04-23T00:00:00+0000": 53,
"2024-04-24T00:00:00+0000": 29,
"2024-04-25T00:00:00+0000": 40
}
}

Information on your n8n setup

  • n8n version:1.38.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via Docker
  • Operating system: Win 11 via WSL

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @PsychoAlex ,

Fields To Include in Split Out node doesn’t work for you?

hello @PsychoAlex

What is the point to split it?
You don’t have an array there, its an object with nested objects. But you can do that with code node

2 Likes

It does not, sadly. The API only returns an object if it contains any data, and some of them are quire rare. The object name is also a concatenation of 3 separate fields, Action:Threat:Reason, so it the number of different permutations is rather large.

Fantastic, thanks. Been trying to manage it in JS, but my JS is rather rusty to say the least.

I need to separate it out to make the reporting much easier, now I can parse each object as a separate item, rather than having to write the logic to process the entire set as one dataset.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.