Getting Value of JSON with random key

Hi!

I have an http request node which returns a json with the following structure

[

{

"RANDOM_KEY": {

"name": "AAAAAAA" ,

"value": "1111" 
}

}

]

And I am connecting the http request node to a set node where I need to grab the "name" value from the http request node. The problem is that as the RANDOM_KEY value changes with every run I am not getting the value I need.

Any ideas how can I achieve this?
Thanks in advance!

Welcome to the community @yakito

Add a function node after the HTTP node, with the following code:

const data = items[0].json

const key = Object.keys(data)[0]

return [
  {
    json: data[key]
  }
]
Example workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      \n\n\"RANDOM_KEY\": {\n\n\"name\": \"AAAAAAA\" ,\n\n\"value\": \"1111\" \n}\n\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        570,
        300
      ],
      "notesInFlow": true,
      "notes": "HTTP mockup"
    },
    {
      "parameters": {
        "functionCode": "const data = items[0].json\n\nconst key = Object.keys(data)[0]\n\n\nreturn [\n  {\n    json: data[key]\n  }\n]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks a lot! that was it! @RicardoE105

Great that it worked. Have fun.

2 Likes