Trouble with $jmespath() expression

Describe the question

I am trying to use $jmespath() in the following situation, but always getting either null or invalid syntax. So the output from another node is something like this:

{
  "json": {
    "data": {
      "key": "question_1",
      "label": "Are you responsible?",
      "value": "bd67ae50",
      "options": [
        {
          "id": "9e77edfb",
          "text": "Yes"
        },
        {
          "id": "0080beff",
          "text": "No"
        },
        {
          "id": "bd67ae50",
          "text": "N/A"
        }
      ]
    }
  }

So I am trying to extract the selected text value by comparing value of value. The expression I have which returns nothing is as follows.

{{ $jmespath($json.data.options, "[?id==`$json.data.value`].text") }}

But if I hard code the value as follows (which is obviously not possible in dynamic situations), it does return "N/A".

{{ $jmespath($json.data.options, "[?id==`bd67ae50`].text") }}

So how can I achieve this in an expression?

Information on your n8n setup

  • n8n version: 0.214.2
  • Database you’re using (default: SQLite): postgres
  • Running n8n with the execution process [own(default), main]: not sure
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: docker

I tried with string interpolation but couldn’t get it working

{{ $jmespath($json.data.options, `[?id=='${ $json.data.value }'].text`) }}

String concatenation works though:

{{ $jmespath($json.data.options, "[?id==`" + $json.data.value + "`].text") }}
5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.