Need JSON Output but it converted into Array

call My JSON API via HTTP Node
and Get the JSON value via SET Note
But it Gets as Array

I want Pure JSON Output
because I need to write custom Functions

Hey @mskian!

Can you be a bit more specific as to what exactly you want to do? From what you have described it seems that the API is sending you the data in an array. The Set node is just returning you the data. The Set node will not change the data type. You can use the Function node to change the data type of the data you received and then write your custom functions.

1 Like

Hi @mskian! As @harshil1712 mentioned, it’s likely that the API that you are getting the data from is sending the data as an array and that is what is returned by the HTTP Request, and in turn, by the Set node.

To convert the array into rows, you’ll need to use a Function node. You can use a for loop to iterate through your array to do that. Here’s an example workflow that converts an array into individual rows.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{json: {name: [\"n8n\", \"nodemotion\", \"nathan\", \"anotherItem\"]}}];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const newItems = [];\n\nfor (let i=0;i<items[0].json.name.length;i++) {\n  newItems.push({json: {name: items[0].json.name[i]}});\n}\n\nreturn newItems;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Please note that the JavaScript code might differ for you based on how exactly the API is returning data. Hope that helps! :slight_smile:

1 Like

ya got it from here

That is great! Have fun!

2 Likes