Json result to array

Hi there,
I am hoping someone can help me.
I have a mysql query thar returns a set of rows/columns but is not returns as an array - is there a way I can do this? Example of my result would be like this:

 {
          "name": "",
          "nodes": [
            {
              "parameters": {},
              "name": "Start",
              "type": "n8n-nodes-base.start",
              "typeVersion": 1,
              "position": [
                250,
                300
              ]
            },
            {
              "parameters": {
                "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      ignoreData: 'whatever1'\n    }\n  },\n  {\n    json: {\n      id: 2,\n      ignoreData: 'whatever2'\n    }\n  }\n]"
              },
              "name": "Mock Data Sheets",
              "type": "n8n-nodes-base.function",
              "typeVersion": 1,
              "position": [
                510,
                300
              ]
            }
          ],
          "connections": {
            "Mock Data Sheets": {
              "main": [
                []
              ]
            },
            "Start": {
              "main": [
                [
                  {
                    "node": "Mock Data Sheets",
                    "type": "main",
                    "index": 0
                  }
                ]
              ]
            }
          },
          "active": false,
          "settings": {}
      }

I would want it to be something like this instead:

{
  "name": "",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n\n    json: {\n      Result:{\n      id: 1,\n      ignoreData: 'whatever1'\n    }\n     }\n  },\n  {\n    json: {\n    Result:{\n      id: 2,\n      ignoreData: 'whatever2'\n    }\n    }\n  }\n]"
      },
      "name": "Mock Data Sheets",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        510,
        300
      ]
    }
  ],
  "connections": {
    "Mock Data Sheets": {
      "main": [
        []
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Mock Data Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {}
}

can anyone assist?

You can do the following:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      ignoreData: 'whatever1'\n    }\n  },\n  {\n    json: {\n      id: 2,\n      ignoreData: 'whatever2'\n    }\n  }\n]"
      },
      "name": "Mock Data Sheets",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        350
      ]
    },
    {
      "parameters": {
        "functionCode": "return items.map(item => { \n  return { \n    json: { \n      Result: item.json,\n    }\n  };\n});"
      },
      "name": "Convert Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        350
      ]
    }
  ],
  "connections": {
    "Mock Data Sheets": {
      "main": [
        [
          {
            "node": "Convert Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes