# Is switch the proper node to split and object?

**URL:** <https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231>\
**Category:** General\
**Created:** [6 May 2023 19:42 UTC](https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231 "2023-05-06T19:42:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [6 May 2023 19:42 UTC](https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231/1 "2023-05-06T19:42:46Z")

</div>

This is a silly question since a split node exist, but I wanna explain what are my goals.

I have an object like:

```auto
msg.payload = {
  "speed": {
    "_set": 8.5,
    "_get": 0
  },
  "info": {
    "current": 0,
    "Vdc": 321,
    "state": 0,
    "Vout": 0,
    "torque": 0,
    "Pout": 0,
    "pf": 0
  }
}

```

I wanna access the values of `speed._get` and `info.current`.  
I'm using Edit change node to get those values. Is there a way to use switch with two outputs?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02284bd00af1df6161a35fc322e6380b89a98192.png)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [6 May 2023 19:59 UTC](https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231/2 "2023-05-06T19:59:23Z")

</div>

Put simply no.

Do you actually need those values to be in the msg.payload, if not just access them where they are.  
If you do you could send the same msg to two change nodes.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 May 2023 20:52 UTC](https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231/3 "2023-05-06T20:52:49Z")

</div>

You could combine a split with a switch.  
e.g.

```auto
[{"id":"17576336cded5386","type":"inject","z":"1d319bc3005a51a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"speed\": { \"_set\": 8.5, \"_get\": 0 }, \"info\": { \"current\": 0, \"Vdc\": 321, \"state\": 0, \"Vout\": 0, \"torque\": 0, \"Pout\": 0, \"pf\": 0 } }","payloadType":"json","x":90,"y":740,"wires":[["f5ff82e8913a92e0"]]},{"id":"f5ff82e8913a92e0","type":"split","z":"1d319bc3005a51a2","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":210,"y":740,"wires":[["4ae02073b26113f2"]]},{"id":"4ae02073b26113f2","type":"switch","z":"1d319bc3005a51a2","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"speed","vt":"str"},{"t":"eq","v":"info","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":330,"y":740,"wires":[["5980bfbc3811ca4b"],["c66dee150c0135b4"]]},{"id":"5980bfbc3811ca4b","type":"debug","z":"1d319bc3005a51a2","name":"debug 298","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload._set","statusType":"msg","x":550,"y":700,"wires":[]},{"id":"c66dee150c0135b4","type":"debug","z":"1d319bc3005a51a2","name":"debug 299","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.current","statusType":"msg","x":550,"y":760,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 July 2023 20:53 UTC](https://discourse.nodered.org/t/is-switch-the-proper-node-to-split-and-object/78231/4 "2023-07-05T20:53:48Z")

</div>

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