[{"data":1,"prerenderedAt":220},["ShallowReactive",2],{"node-red-\u002Fnode-red\u002Fcore-nodes\u002Fswitch":3},{"id":4,"title":5,"body":6,"description":204,"extension":213,"meta":214,"navigation":215,"path":216,"seo":217,"stem":218,"__hash__":219},"nodeRed\u002Fnode-red\u002Fcore-nodes\u002Fswitch.md","Node-RED - Switch Node",{"type":7,"value":8,"toc":203},"minimark",[9,14,19,23,26,33,39,45,51,57,63,67,74,79,83],[10,11,13],"h1",{"id":12},"switch","Switch",[15,16,18],"h2",{"id":17},"what-is-the-switch-node-used-for-in-node-red","What is the Switch node used for in Node-RED",[20,21,22],"p",{},"The Switch node allows you to route messages based on certain conditions. It acts as a decision-making tool within your flow, allowing you to define rules for directing messages to different output branches.",[20,24,25],{},"Here are some common use cases for using the Switch node in Node-RED:",[20,27,28,32],{},[29,30,31],"strong",{},"Message Filtering",": You can use the Switch node to filter messages based on specific criteria. For example, you might want to filter out messages that don't meet a certain threshold or that don't contain certain keywords.",[20,34,35,38],{},[29,36,37],{},"Conditional Routing",": The Switch node enables you to route messages down different paths in your flow based on conditions. You can set up rules that determine which output branch a message should be sent to, depending on its content or properties.",[20,40,41,44],{},[29,42,43],{},"Event Processing",": If you're working with events or data streams, the Switch node can help you process different types of events differently. For instance, you might have events related to temperature and humidity readings, and you want to process them separately.",[20,46,47,50],{},[29,48,49],{},"Value Conversion",": In cases where you need to convert values from one format to another, the Switch node can route messages to different converters based on the incoming value's properties.",[20,52,53,56],{},[29,54,55],{},"Error Handling",": When working with data or APIs, you might receive error messages that need to be handled differently from regular data. The Switch node can direct error messages to a separate branch for appropriate handling.",[20,58,59,62],{},[29,60,61],{},"Language or Region-Based Processing",": In applications involving localization or multilingual support, the Switch node can route messages based on language or region information in the message.",[15,64,66],{"id":65},"examples","Examples",[20,68,69],{},[70,71],"img",{"alt":72,"src":73},"Switch Node Example","\u002Fnode-red\u002Fcore-nodes\u002Fimages\u002Fswitch-example-2.png",[75,76],"render-flow",{":height":77,"flow":78},"200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xNDAxZDY2NDYxNmZjOTU2IiwibmFtZSI6IkJlbG93IDI1wrBDIiwiYWN0aXZlIjp0cnVlLCJ0b3NpZGViYXIiOnRydWUsImNvbnNvbGUiOmZhbHNlLCJ0b3N0YXR1cyI6ZmFsc2UsImNvbXBsZXRlIjoicGF5bG9hZCIsInRhcmdldFR5cGUiOiJtc2ciLCJzdGF0dXNWYWwiOiIiLCJzdGF0dXNUeXBlIjoiYXV0byIsIngiOjY4MCwieSI6MTYwLCJ3aXJlcyI6W119LHsiaWQiOiJhYm92ZS0yNS1ub2RlIiwidHlwZSI6ImRlYnVnIiwieiI6IjE0MDFkNjY0NjE2ZmM5NTYiLCJuYW1lIjoiQWJvdmUgMjXCsEMiLCJhY3RpdmUiOnRydWUsInRvc2lkZWJhciI6dHJ1ZSwiY29uc29sZSI6ZmFsc2UsInRvc3RhdHVzIjpmYWxzZSwiY29tcGxldGUiOiJwYXlsb2FkIiwidGFyZ2V0VHlwZSI6Im1zZyIsIngiOjY4MCwieSI6MjQwLCJ3aXJlcyI6W119XQ==",[15,80,82],{"id":81},"node-documentation","Node Documentation",[84,85,88,91,92,91,97,91,100,91,103,91,106,91,111,91,114,91,145,91,149,91,161,91,182,91,186,91,193],"div",{"className":86},[87],"core-node-doc",[20,89,90],{},"Route messages based on their property values or sequence position."," ",[93,94,96],"h3",{"id":95},"details","Details",[20,98,99],{},"When a message arrives, the node will evaluate each of the defined rules\nand forward the message to the corresponding outputs of any matching rules.",[20,101,102],{},"Optionally, the node can be set to stop evaluating rules once it finds one\nthat matches.",[20,104,105],{},"The rules can be evaluated against an individual message property, a flow or global\ncontext property, environment variable or the result of a JSONata expression.",[107,108,110],"h4",{"id":109},"rules","Rules",[20,112,113],{},"There are four types of rule:",[115,116,117,125,131,138],"ol",{},[118,119,120,124],"li",{},[121,122,123],"b",{},"Value"," rules are evaluated against the configured property",[118,126,127,130],{},[121,128,129],{},"Sequence"," rules can be used on message sequences, such as those\ngenerated by the Split node",[118,132,133,134,137],{},"A JSONata ",[121,135,136],{},"Expression"," can be provided that will be evaluated\nagainst the whole message and will match if the expression returns\na true value.",[118,139,140,141,144],{},"An ",[121,142,143],{},"Otherwise"," rule can be used to match if none of the preceeding\nrules have matched.",[107,146,148],{"id":147},"notes","Notes",[20,150,151,152,156,157,160],{},"The ",[153,154,155],"code",{},"is true\u002Ffalse"," and ",[153,158,159],{},"is null"," rules perform strict\ncomparisons against those types. They do not convert between types.",[20,162,151,163,156,166,169,170,173,174,177,178,181],{},[153,164,165],{},"is empty",[153,167,168],{},"is not empty"," rules can be used to test the length of Strings, Arrays and Buffers, or the number of properties an Object has. Neither rule will pass if the property being tested has a ",[153,171,172],{},"boolean",", ",[153,175,176],{},"null"," \nor ",[153,179,180],{},"undefined"," value.",[107,183,185],{"id":184},"handling-message-sequences","Handling message sequences",[20,187,188,189,192],{},"By default, the node does not modify the ",[153,190,191],{},"msg.parts"," property of messages\nthat are part of a sequence.",[20,194,151,195,198,199,202],{},[121,196,197],{},"recreate message sequences"," option can be enabled to generate new message sequences\nfor each rule that matches. In this mode, the node will buffer the entire incoming\nsequence before sending the new sequences on. The runtime setting ",[153,200,201],{},"nodeMessageBufferMaxLength","\ncan be used to limit how many messages nodes will buffer.",{"title":204,"searchDepth":205,"depth":205,"links":206},"",2,[207,208,209],{"id":17,"depth":205,"text":18},{"id":65,"depth":205,"text":66},{"id":81,"depth":205,"text":82,"children":210},[211],{"id":95,"depth":212,"text":96},3,"md",{},true,"\u002Fnode-red\u002Fcore-nodes\u002Fswitch",{"title":5,"description":204},"node-red\u002Fcore-nodes\u002Fswitch","0zXqp4OrIj2RbjEazBsHdGQ91F-hZh9Jhi_S6l3JJV0",1780070556252]