Hi -
I'm new to Node-RED and am trying to use JSONata in a Switch node to route my msg.payload. I found this in my search and attempted to replicate it for my data. Though the JSONata Test reports True, my payload goes no further. The JSON is a vm_info including tags created by Ansible..
My attempt to replicate the example in the linked post with JSONata in the Property field:
true in tags[*].$contains($.name, "AnsibleManaged")
ref: JSONata Exerciser
Additionally, I have tried the following syntax as a JSONata rule:
"AnsibleManaged" in tags.name
ref: JSONata Exerciser
and
true in tags[*].$contains($.name, "AnsibleManaged")
... these both evaluate to True and pass the test against my JSON.
I'm obviously not doing something correctly here and would appreciate any help. Thanks!
[{"id":"c82f6541f05e4529","type":"tab","label":"Debug with Functions","disabled":false,"info":"","env":[]},{"id":"b5ec2a3d5867fecd","type":"inject","z":"c82f6541f05e4529","name":"Send Test vm_info Payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"guest_name\":\"DebugNode-RED\",\"guest_fullname\":\"Ubuntu Linux (64-bit)\",\"power_state\":\"poweredOn\",\"ip_address\":\"192.168.50.254\",\"mac_address\":[\"00:50:54:87:bc:74\"],\"uuid\":\"4207b810-fc10-a2ad-dd5d-ced4ba83d953\",\"vm_network\":{\"00:50:56:87:bc:74\":{\"ipv4\":[\"192.168.50.254\"],\"ipv6\":[\"fe80::250:54ff:fe87:bc74\"]}},\"esxi_hostname\":\"massstorage.homelab.bjzy.me\",\"datacenter\":\"Home Lab Datacenter\",\"cluster\":\"Home Lab CL1\",\"resource_pool\":null,\"attributes\":{},\"tags\":[{\"id\":\"urn:vmomi:InventoryServiceTag:1c7ec29c-cfcf-4e81-8bc5-043505a73616:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"AnsibleManaged\",\"description\":\"Ansible is used to configure this resource\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:0fb3a150-093d-4415-9465-ceacce0f28e1:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"Terraform\",\"description\":\"Indicates VM was created and state is managed by Terraform.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:f4360074-ff82-46f2-b7da-6fe1bd91defa:GLOBAL\",\"category_name\":\"Environment\",\"name\":\"Development\",\"description\":\"Formal Dev environment. Build and implement here first.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:a968e543-f640-4f6e-a9ee-cd3c5bc234ee:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:52b62f3e-ca99-4416-ab0f-da6b4eca462d:GLOBAL\",\"category_name\":\"Monitoring\",\"name\":\"bootNotify\",\"description\":\"Host should send an alert on boot. This tag will trigger bootNotify install.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:6cd83cd3-adfd-4247-8776-322a5ff233ff:GLOBAL\"}],\"folder\":\"/Home Lab Datacenter/vm\",\"moid\":\"vm-25928\",\"datastore_url\":[{\"name\":\"NVMe-c\",\"url\":\"/vmfs/volumes/60bd10bb-fe1c3d76-e39d-0cc47a172710\"}],\"allocated\":{}}","payloadType":"json","x":230,"y":180,"wires":[["f43467b9f14d281b"]]},{"id":"f43467b9f14d281b","type":"switch","z":"c82f6541f05e4529","name":"Tag Flow Control [JSONata Function Rule]","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"true in tags[*].$contains($.name, \"AnsibleManaged\")","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":560,"y":180,"wires":[["044e3cebb1590862"]]},{"id":"044e3cebb1590862","type":"debug","z":"c82f6541f05e4529","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":180,"wires":[]},{"id":"69a0012070b5be7f","type":"inject","z":"c82f6541f05e4529","name":"Send Test vm_info Payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"guest_name\":\"DebugNode-RED\",\"guest_fullname\":\"Ubuntu Linux (64-bit)\",\"power_state\":\"poweredOn\",\"ip_address\":\"192.168.50.254\",\"mac_address\":[\"00:50:54:87:bc:74\"],\"uuid\":\"4207b810-fc10-a2ad-dd5d-ced4ba83d953\",\"vm_network\":{\"00:50:56:87:bc:74\":{\"ipv4\":[\"192.168.50.254\"],\"ipv6\":[\"fe80::250:54ff:fe87:bc74\"]}},\"esxi_hostname\":\"massstorage.homelab.bjzy.me\",\"datacenter\":\"Home Lab Datacenter\",\"cluster\":\"Home Lab CL1\",\"resource_pool\":null,\"attributes\":{},\"tags\":[{\"id\":\"urn:vmomi:InventoryServiceTag:1c7ec29c-cfcf-4e81-8bc5-043505a73616:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"AnsibleManaged\",\"description\":\"Ansible is used to configure this resource\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:0fb3a150-093d-4415-9465-ceacce0f28e1:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"Terraform\",\"description\":\"Indicates VM was created and state is managed by Terraform.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:f4360074-ff82-46f2-b7da-6fe1bd91defa:GLOBAL\",\"category_name\":\"Environment\",\"name\":\"Development\",\"description\":\"Formal Dev environment. Build and implement here first.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:a968e543-f640-4f6e-a9ee-cd3c5bc234ee:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:52b62f3e-ca99-4416-ab0f-da6b4eca462d:GLOBAL\",\"category_name\":\"Monitoring\",\"name\":\"bootNotify\",\"description\":\"Host should send an alert on boot. This tag will trigger bootNotify install.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:6cd83cd3-adfd-4247-8776-322a5ff233ff:GLOBAL\"}],\"folder\":\"/Home Lab Datacenter/vm\",\"moid\":\"vm-25928\",\"datastore_url\":[{\"name\":\"NVMe-c\",\"url\":\"/vmfs/volumes/60bd10bb-fe1c3d76-e39d-0cc47a172710\"}],\"allocated\":{}}","payloadType":"json","x":230,"y":280,"wires":[["647ed971a5cc398e"]]},{"id":"647ed971a5cc398e","type":"switch","z":"c82f6541f05e4529","name":"Tag Flow Control [JSONata Property]","property":"true in tags[*].$contains($.name, \"AnsibleManaged\")","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":280,"wires":[["92992e64d5c23f3b"]]},{"id":"92992e64d5c23f3b","type":"debug","z":"c82f6541f05e4529","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":280,"wires":[]},{"id":"a7b171a4741c25fb","type":"inject","z":"c82f6541f05e4529","name":"Send Test vm_info Payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"guest_name\":\"DebugNode-RED\",\"guest_fullname\":\"Ubuntu Linux (64-bit)\",\"power_state\":\"poweredOn\",\"ip_address\":\"192.168.50.254\",\"mac_address\":[\"00:50:54:87:bc:74\"],\"uuid\":\"4207b810-fc10-a2ad-dd5d-ced4ba83d953\",\"vm_network\":{\"00:50:56:87:bc:74\":{\"ipv4\":[\"192.168.50.254\"],\"ipv6\":[\"fe80::250:54ff:fe87:bc74\"]}},\"esxi_hostname\":\"massstorage.homelab.bjzy.me\",\"datacenter\":\"Home Lab Datacenter\",\"cluster\":\"Home Lab CL1\",\"resource_pool\":null,\"attributes\":{},\"tags\":[{\"id\":\"urn:vmomi:InventoryServiceTag:1c7ec29c-cfcf-4e81-8bc5-043505a73616:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"AnsibleManaged\",\"description\":\"Ansible is used to configure this resource\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:0fb3a150-093d-4415-9465-ceacce0f28e1:GLOBAL\",\"category_name\":\"Automation\",\"name\":\"Terraform\",\"description\":\"Indicates VM was created and state is managed by Terraform.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:f4360074-ff82-46f2-b7da-6fe1bd91defa:GLOBAL\",\"category_name\":\"Environment\",\"name\":\"Development\",\"description\":\"Formal Dev environment. Build and implement here first.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:a968e543-f640-4f6e-a9ee-cd3c5bc234ee:GLOBAL\"},{\"id\":\"urn:vmomi:InventoryServiceTag:52b62f3e-ca99-4416-ab0f-da6b4eca462d:GLOBAL\",\"category_name\":\"Monitoring\",\"name\":\"bootNotify\",\"description\":\"Host should send an alert on boot. This tag will trigger bootNotify install.\",\"category_id\":\"urn:vmomi:InventoryServiceCategory:6cd83cd3-adfd-4247-8776-322a5ff233ff:GLOBAL\"}],\"folder\":\"/Home Lab Datacenter/vm\",\"moid\":\"vm-25928\",\"datastore_url\":[{\"name\":\"NVMe-c\",\"url\":\"/vmfs/volumes/60bd10bb-fe1c3d76-e39d-0cc47a172710\"}],\"allocated\":{}}","payloadType":"json","x":210,"y":380,"wires":[["4f6f79d376800ade"]]},{"id":"4f6f79d376800ade","type":"switch","z":"c82f6541f05e4529","name":"Tag Flow Control [JSONata Rule w/o Functions]","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"\"AnsibleManaged\" in tags.name","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":560,"y":380,"wires":[["655916a4baf08d8b"]]},{"id":"655916a4baf08d8b","type":"debug","z":"c82f6541f05e4529","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":380,"wires":[]}]
{
"guest_name": "DebugNode-RED",
"guest_fullname": "Ubuntu Linux (64-bit)",
"power_state": "poweredOn",
"ip_address": "192.168.50.254",
"mac_address": [
"00:50:54:87:bc:74"
],
"uuid": "4207b810-fc10-a2ad-dd5d-ced4ba83d953",
"vm_network": {
"00:50:56:87:bc:74": {
"ipv4": [
"192.168.50.254"
],
"ipv6": [
"fe80::250:54ff:fe87:bc74"
]
}
},
"esxi_hostname": "massstorage.homelab.bjzy.me",
"datacenter": "Home Lab Datacenter",
"cluster": "Home Lab CL1",
"resource_pool": null,
"attributes": {},
"tags": [
{
"id": "urn:vmomi:InventoryServiceTag:1c7ec29c-cfcf-4e81-8bc5-043505a73616:GLOBAL",
"category_name": "Automation",
"name": "AnsibleManaged",
"description": "Ansible is used to configure this resource",
"category_id": "urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL"
},
{
"id": "urn:vmomi:InventoryServiceTag:0fb3a150-093d-4415-9465-ceacce0f28e1:GLOBAL",
"category_name": "Automation",
"name": "Terraform",
"description": "Indicates VM was created and state is managed by Terraform.",
"category_id": "urn:vmomi:InventoryServiceCategory:dcf78d63-1f5b-412f-87e6-35c17fe7e363:GLOBAL"
},
{
"id": "urn:vmomi:InventoryServiceTag:f4360074-ff82-46f2-b7da-6fe1bd91defa:GLOBAL",
"category_name": "Environment",
"name": "Development",
"description": "Formal Dev environment. Build and implement here first.",
"category_id": "urn:vmomi:InventoryServiceCategory:a968e543-f640-4f6e-a9ee-cd3c5bc234ee:GLOBAL"
},
{
"id": "urn:vmomi:InventoryServiceTag:52b62f3e-ca99-4416-ab0f-da6b4eca462d:GLOBAL",
"category_name": "Monitoring",
"name": "bootNotify",
"description": "Host should send an alert on boot. This tag will trigger bootNotify install.",
"category_id": "urn:vmomi:InventoryServiceCategory:6cd83cd3-adfd-4247-8776-322a5ff233ff:GLOBAL"
}
],
"folder": "/Home Lab Datacenter/vm",
"moid": "vm-25928",
"datastore_url": [
{
"name": "NVMe-c",
"url": "/vmfs/volumes/60bd10bb-fe1c3d76-e39d-0cc47a172710"
}
],
"allocated": {}
}
cc @ E1cid