Help with transforming data

Describe the problem/error/question

Hi, I’ve been trying to transform data but without any success. I’m trying to generate statistics for which I need the following objects grouped together by their id (reduced them a bit). I’ve been trying to get forward using multiple solutions provided by the forum for similar problems, and some JavaScript functions which chatgpt and google bard created. Sadly I got none of them to work…
It would be great if anybody could help me out!

That’s my data:

[
  {
    "maps": {
      "abgeschlosseneSchichten": 11,
      "gestarteteSchichten": 15,
      "id": 77725
    },
    "date": "2023-12-31",
    "dateToMillis": 1703977200000
  },
  {
    "maps": {
      "abgeschlosseneSchichten": 35,
      "gestarteteSchichten": 40,
      "id": 77726
    },
    "date": "2023-12-31",
    "dateToMillis": 1703977200000
  },
  {
    "maps": {
      "abgeschlosseneSchichten": 8,
      "gestarteteSchichten": 11,
      "id": 77725
    },
    "date": "2024-01-01",
    "dateToMillis": 1704063600000
  },
  {
    "maps": {
      "abgeschlosseneSchichten": 35,
      "gestarteteSchichten": 42,
      "id": 77726
    },
    "date": "2024-01-01",
    "dateToMillis": 1704063600000
  }
]

The format I’m trying to get

[
  {
    "map": 77725,
    "data": [
      {
        "maps": {
          "abgeschlosseneSchichten": 11,
          "gestarteteSchichten": 15,
          "id": 77725
        },
        "date": "2023-12-31",
        "dateToMillis": 1703977200000
      },
      {
        "maps": {
          "abgeschlosseneSchichten": 8,
          "gestarteteSchichten": 11,
          "id": 77725
        },
        "date": "2024-01-01",
        "dateToMillis": 1704063600000
      }
    ]
  },
  {
    "map": 77726,
    "data": [
      {
        "maps": {
          "abgeschlosseneSchichten": 35,
          "gestarteteSchichten": 40,
          "id": 77726
        },
        "date": "2023-12-31",
        "dateToMillis": 1703977200000
      },
      {
        "maps": {
          "abgeschlosseneSchichten": 35,
          "gestarteteSchichten": 42,
          "id": 77726
        },
        "date": "2024-01-01",
        "dateToMillis": 1704063600000
      }
    ]
  }
]

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:

Had a little break and there I had the solution: With an “Item lists” node I removed duplicate maps.id, then looped through them and in each loop, I called all my original data again and filtered them by the id that’s currently running through the loop (for anyone who might’ve encountered the same problem).

1 Like

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