IF node: Having issues with "contains" conditional

Hi,
I’ve a very simple IF node. The value of t1 is set as "IOC Test". But when I try to do a conditonal using “Contains” it is not finding it. It comes correctly in the “false” output, but I expected it to be in True


name	"if_test"
nodes	
0	
parameters	{}
name	"Start"
type	"n8n-nodes-base.start"
typeVersion	1
position	
0	240
1	300
1	
parameters	
values	
string	
0	
name	"t1"
value	"\"IOC test\""
options	{}
name	"Set"
type	"n8n-nodes-base.set"
typeVersion	1
position	
0	460
1	300
2	
parameters	
conditions	
string	
0	
value1	"t1"
operation	"contains"
value2	"IOC"
name	"IF"
type	"n8n-nodes-base.if"
typeVersion	1
position	
0	680
1	300
connections	
Start	
main	
0	
0	
node	"Set"
type	"main"
index	0
Set	
main	
0	
0	
node	"IF"
type	"main"
index	0
active	false
settings	{}
id	7

Instead of string “t1” you want to put their variable $JSON['t1']
Check this workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -2460,
        720
      ]
    },
    {
      "parameters": {
        "resource": "all",
        "limit": 1,
        "additionalFields": {}
      },
      "name": "Hacker News",
      "type": "n8n-nodes-base.hackerNews",
      "typeVersion": 1,
      "position": [
        -2160,
        740
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"title\"]}}",
              "operation": "contains",
              "value2": "Hawking"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1940,
        740
      ]
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/922278105257766973/zRv_-XE9b_Az67k6WAEJWvUB-t6TSTJJMc-yRH9NSEfMN_NBia6U4W8hyBgRHEQzX7V0",
        "text": "true"
      },
      "name": "Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        -1660,
        600
      ]
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/922278105257766973/zRv_-XE9b_Az67k6WAEJWvUB-t6TSTJJMc-yRH9NSEfMN_NBia6U4W8hyBgRHEQzX7V0",
        "text": "false"
      },
      "name": "Discord1",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        -1680,
        800
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Hacker News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hacker News": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Discord",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Discord1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Or this GIF how to do this: Imgur: The magic of the Internet

You mean to say

={{$json[\"t1\"]}}

Yes, :grinning:

Just follow GIF, I think it easier way than rewriting this.

Is it work?

1 Like

It actually has to be:

{{$json["t1"]}}

Else it would be an invalid expression.

2 Likes

thanks guys, it worked