How to change json property with the value in a text input node?

A simple question: how to change json property with the value in a text input node? I have a button node that generates a json object to send via mqtt. Now I want to use a text input node to change the value of data property in the json structure.

[{"id":"06fef075728b4940","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"83ff9096c1e21e77","type":"ui_button","z":"06fef075728b4940","name":"","group":"1b214600.17935a","order":3,"width":0,"height":0,"passthru":false,"label":"Do stuff","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"{\"nodeId\":\"mqtt\",\"idMessage\":1,\"indexPacket\":1,\"totalPackets\":1,\"packetType\":\"request picture\",\"data\":\"node01\"}","payloadType":"json","topic":"topic","topicType":"msg","x":380,"y":1840,"wires":[["798a720fc67b1a65"]]},{"id":"01709def37f25a38","type":"ui_text_input","z":"06fef075728b4940","name":"","label":"","tooltip":"","group":"1b214600.17935a","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"100","topic":"","sendOnBlur":true,"topicType":"str","x":380,"y":1760,"wires":[[]]},{"id":"798a720fc67b1a65","type":"debug","z":"06fef075728b4940","name":"Button click debug node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":1840,"wires":[]},{"id":"1b214600.17935a","type":"ui_group","name":"Default","tab":"b8fb94f4.0d31d8","order":1,"disp":true,"width":"12","collapse":false},{"id":"b8fb94f4.0d31d8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

How should I do?

  1. Store the text entered somewhere
  2. When the button is pressed
    1. get the text from "somewhere"
    2. update the payload property value

image



Indeed :slight_smile:

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Or without using context storage.

[{"id":"24e9cfc9.5955e","type":"ui_text_input","z":"bf9e1e33.030598","name":"","label":"","tooltip":"","group":"1b214600.17935a","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","sendOnBlur":true,"className":"","topicType":"str","x":300,"y":2340,"wires":[["a5212865.bad108"]]},{"id":"a5212865.bad108","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":2400,"wires":[["db3b6d42.211cb8"]]},{"id":"db3b6d42.211cb8","type":"ui_button","z":"bf9e1e33.030598","name":"","group":"1b214600.17935a","order":3,"width":0,"height":0,"passthru":false,"label":"Do stuff","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"{\"nodeId\":\"mqtt\",\"idMessage\":1,\"indexPacket\":1,\"totalPackets\":1,\"packetType\":\"request picture\",\"data\":\"\"}","payloadType":"json","topic":"topic","topicType":"msg","x":210,"y":2460,"wires":[["2da21935.d25aa6"]]},{"id":"2da21935.d25aa6","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload.data","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":2460,"wires":[["74b6408c.76684"]]},{"id":"74b6408c.76684","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":2460,"wires":[]},{"id":"1b214600.17935a","type":"ui_group","name":"Default","tab":"b8fb94f4.0d31d8","order":1,"disp":true,"width":"12","collapse":false},{"id":"b8fb94f4.0d31d8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

I know :grimacing: I'll take a look to your link. Thanks a lot.

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