How to acess JSON key-value pair

Describe the problem/error/question

I have a Google Docs get node that retrieves data from a document I created, which is connected to a “code in JavaScript node”. My problem is that I can’t access the key-value pair within the returned JSON from the Google Docs node, specifically the “content” property.

From what I searched, the instruction {{$json.content}} should’ve worked, but it doesn’t. I even tried “vanilla” JS implementation, like, response[0].content, but it doesn’t work too.

Could you help me solve this problem?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your c{
  "nodes": [
    {
      "parameters": {},
      "id": "e60b06f1-aa9a-4c83-97ee-dbb9966cdf71",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        240,
        304
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "documentURL":"
      },
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 2,
      "position": [
        416,
        304
      ],
      "id": "9a729eb5-8f19-4c49-910f-bd35562e47cc",
      "name": "Get a document",
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "EAAdt7nuhVRAQwmo",
          "name": "Google Docs account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "/*  let input = {{ $JS }}  $\n\nlet result = Object.fromEntries(\n    input.json.content.split(\"\\n\\n\")\n    .map(pair => {\n        const [header, ...values] = pair.split(\"\\n\");\n        return [header, values.length === 1 ? values[0] : values];\n    })\n);*/\n\n//return { json: result };\n\nreturn {{$json.content}}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        656,
        480
      ],
      "id": "8f9a9985-c22f-4745-8899-7f672b48d4c3",
      "name": "Code in JavaScript"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Get a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a document": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "08b06099ab830e765cbeb31e92aad4577dd661bac1ef6a300cb3385cd45b8290"
  }
}anvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

Hi @rAlexB Welcome!
Have you tried using, $input.first().json.content to get the content property? from that google docs node, as expression like you have shown is not valid inside a code node, basically something like this would be valid:

const content = $input.first().json.content;
// your processing logic here
return [{ json: { content } }];

Hello Anshul, I just tried the instruction you mentioned and it works! Thanks for the help! I hope n8n works a bit more to make it easier while going through the documentation