Mapping Title to Value

I have an spreadsheet that has title as 1st row and values starting from 2nd row

However, on http request, i was returned as following

May i know how do i map the 1st value to 2nd and 3rd and so on to create json values.

for example
image

Why are you using the HTTP node instead of the Google sheets node? The node does the mapping for you.

Hello @RicardoE105 sorry for not explaining in detail earlier.

I was using Lark suite , which comes with their version of sheet. Therefore, I am extracting the data from the Lark suite using http request.

Hi @Benjamin123, so “use first item as keys for all other items” isn’t an option included in the http request node yet. Based on your example data, I’d probably use a bit of custom JS to use the strings in the first array as keys, for example like so:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "functionCode": "let results = [];\n\nitems[0].json[\"data\"][\"valueRange\"][\"values\"].forEach((row, i) => {\n  if (i > 0) {\n    let result = {\n      json: {}\n    };\n    row.forEach((cell, column) => {\n      const columnName = items[0].json[\"data\"][\"valueRange\"][\"values\"][0][column];\n      result.json[columnName] = cell;\n    });\n    results.push(result);\n  }\n});\n\nreturn results;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    data: {\n      valueRange: {\n        values: [[\n          \"ID\",\n          \"Name\"\n        ], [\n          \"1\",\n          \"Foo\"\n        ], [\n          \"2\",\n          \"Bar\"\n        ], [\n          \"3\",\n          \"Baz\"\n        ]]\n      }\n    }\n  }\n}]"
      },
      "name": "Set Dummy Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "let results = [];\n\nitems[0].json[\"data\"][\"valueRange\"][\"values\"].forEach((row, i) => {\n  if (i > 0) {\n    let result = {\n      json: {}\n    };\n    row.forEach((cell, column) => {\n      const columnName = items[0].json[\"data\"][\"valueRange\"][\"values\"][0][column];\n      result.json[columnName] = cell;\n    });\n    results.push(result);\n  }\n});\n\nreturn results;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Dummy Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Dummy Data": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

The above example turns this:

Into this:

2 Likes

@MutedJam thank you very much…it is working

1 Like

Awesome, glad to hear and thanks so much for confirming!