I need to get the count of variables from the query's property of webhook node

I’m trying with this, but doesn’t work
var length = {{$node[“Webhook”].json[“query”].length}};

This is in the FunctionItem node

I make a change, this show me all variables that i put in url.

return item.root.query

But i can’t show the length of this.
I can’t do for example: item.root.query[0], for extract the first element to this object.

Hey @victormiranda, you can count it with {{Object.keys($json["query"]).length}}.

This workflow would solve your problem:

{
  "nodes": [
    {
      "parameters": {
        "path": "0d1cb29e-bfa3-4ee9-bb41-e720c0e306db",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "webhookId": "0d1cb29e-bfa3-4ee9-bb41-e720c0e306db"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "queryCount",
              "value": "={{Object.keys($json[\"query\"]).length}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope that helps! :slight_smile:

1 Like

yes thanks you

and for get the property from a position, like Object.keys($json[“query”])[0] ?

Yup, you can get the first key with {{Object.keys($json["query"])[0]}} and the first value with {{Object.values($node["Webhook"].json["query"])[0]}}.

1 Like

Great to hear! Mind marking the post that solved the question? Would be helpful for other community members to discover the solution as well :slight_smile:

Thanks, the workflow is working

1 Like