# JSON expression instead of many change nodes?

**URL:** <https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088>\
**Category:** General\
**Created:** [3 August 2020 18:37 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088 "2020-08-03T18:37:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)\
**Post date:** [3 August 2020 18:37 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/1 "2020-08-03T18:37:31Z")

</div>

Is it possible to use an expression instead of the plethora of change nodes i've created?  
I'm running into the problem where I want to filter out the output of the change nodes and it's quite cumbersome with that many nodes.

The change nodes are moving two values from an array in a set pattern.

```auto
[{"id":"7e05bfe6.193dd","type":"change","z":"392484c1.36304c","name":"1","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload[0][1]","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload[1][1]","tot":"msg"},{"t":"set","p":"payload1","pt":"msg","to":"payload[2][1]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1100,"wires":[["52f74198.0e62d"]]},{"id":"3628255f.ec331a","type":"change","z":"392484c1.36304c","name":"2","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload[0][2]","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload[1][2]","tot":"msg"},{"t":"set","p":"payload1","pt":"msg","to":"payload[2][2]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1140,"wires":[["52f74198.0e62d"]]}]

```

A visual of my flow.

 ![Screen Shot 2020-08-03 at 12.36.26 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ec84d509aaf9e8bfbbd545c1c7008026988a4de3.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 August 2020 18:43 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/2 "2020-08-03T18:43:42Z")

</div>

Can you provide some data that is going into the flow?

---

<div class="post-metadata">

**Author:** ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)\
**Post date:** [3 August 2020 19:37 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/3 "2020-08-03T19:37:39Z")

</div>

It's a payload with three arrays.

![Screen Shot 2020-08-03 at 1.36.56 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f50eb4fd7c927a3c6bd796cbd6e3893c4d40e396.png)

```auto
[["(20 TOTAL)","robot_name_tv","dashboard_toggle_text","arc","dashboard_start_button_text","tv_menu_text","tv_menu_text","tv_menu_text","tv_menu_text","tv_menu_text","dashboard_toggle","custom_switch_toggle_text_off","dashboard_next_operation_text_top_title2","dashboard_next_operation_text_day2","dashboard_next_operation_text_top_date2","dashboard_next_operation_text_top_time2","dashboard_next_operation_text_top_title","dashboard_next_operation_text_day","dashboard_next_operation_text_top_date","dashboard_next_operation_text_top_time","dashboard_robot_location",{"s":"","orig":"","length":0},{"s":"","orig":"","length":0}],["(20 TOTAL)","RC","SCHEDULE","Mow","Mow","Help Center","Menu","Schedule","History","Manual","Schedule off","OFF","Previous operation","---","--- --","--:--","Next operation","---","--- --","--:--","Connecting"],["(20 TOTAL)","74,154","413,286","540,1128","279,1127","496,1707","243,1772","720,1014","768,1271","687,1519","652,293","692,289","217,403","130,504","276,466","270,523","698,403","648,504","794,466","788,523","870,1880"]]

```

The change node combines array 0,0; 1,0; 2,0. Then 0,1; 1,1; 2,1. Then 0,2; 1,2; 2,2 and so on.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 August 2020 19:49 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/4 "2020-08-03T19:49:32Z")

</div>

I notice that payload[0] has 23 items while [1] and [2] have only 20. How do you handle that?

---

<div class="post-metadata">

**Author:** ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)\
**Post date:** [3 August 2020 19:52 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/5 "2020-08-03T19:52:08Z")

</div>

They are just empty. I think I got my problem solved in my other thread by Steve-Mcl.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 August 2020 20:01 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/6 "2020-08-03T20:01:09Z")

</div>

Great! Just to let you know, your `change` nodes would not have worked the w ![Screen Shot 2020-08-03 at 3.56.23 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/cee755da1f255122ccf4d1950a15f32683b6e819.png) ay you had them.

Rule 2 will set msg.payload to the contents of msg.payload[1][1]  
Rule 3 wants to set msg.payload1 to the contents of msg.payload[2][1] but msg.payload has been overwritten by the contents of msg.payload[1][1].

To do this you could do something like this:  
 ![Screen Shot 2020-08-03 at 4.00.31 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c3b1717f212dd57a3276df6ac81f23862aeb8f1c.png)

---

<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:** [2 October 2020 20:01 UTC](https://discourse.nodered.org/t/json-expression-instead-of-many-change-nodes/31088/7 "2020-10-02T20:01:23Z")

</div>

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