Json split question (mqtt)

I am receiving the following json from a Firebase database:

I needed to create some function that separated the contents of "PLACE1A" and "PLACE1B" so that they were shown in two different payloads.

Can anyone help me with any tips or how can I do this?

I'm still quite a beginner in node-red.


By using the "move" command of the change node you can move the required part of the data to the payload

[{"id":"1f8c49fd.4ac0a6","type":"function","z":"78abef.11f5941","name":"","func":"msg.payload = {\n    data1:{\n        something:123,\n        other_thing:1234,\n        description:\"this is data1\"\n    },\n    data2:{\n        something:321,\n        other_thing:4321,\n        description:\"this is data2\"\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":880,"wires":[["8a920107.48fb8","80e674e3.71dab8","9ed74bba.b812e8"]]},{"id":"8a920107.48fb8","type":"debug","z":"78abef.11f5941","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":840,"wires":[]},{"id":"e6bfb655.18df48","type":"inject","z":"78abef.11f5941","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":880,"wires":[["1f8c49fd.4ac0a6"]]},{"id":"80e674e3.71dab8","type":"change","z":"78abef.11f5941","name":"","rules":[{"t":"move","p":"payload.data1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":880,"wires":[["c1e2fff7.bc9"]]},{"id":"9ed74bba.b812e8","type":"change","z":"78abef.11f5941","name":"","rules":[{"t":"move","p":"payload.data2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":920,"wires":[["9722be2b.e3349"]]},{"id":"c1e2fff7.bc9","type":"debug","z":"78abef.11f5941","name":"FIRST","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":880,"wires":[]},{"id":"9722be2b.e3349","type":"debug","z":"78abef.11f5941","name":"SECOND","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":920,"wires":[]}]

Thanks, hotNipi!

This helped me, but in my place1, there is a "-" in the front, "-PLACE1A" and with that character in the front it apparently doesn't work. Is there any alternative?

Thank you again!

Then you'll need to access the property like this

It worked, hotNipi.

Thank you so much!

Hello again

The solution proposed by hotNipi worked, I can separate the json and send the information for each specific topic by mqtt:

Is there any other way to do this? I ask why I would like to make it a little more "automated", for example:

I tried to make json separate with the split node, and to copy the key:


Then I tried to set the topic with this key value and added it to the mqtt output node, with the topic field blank, so that the data could be sent.

In msg.payload it works, the data is separated for each key. But mqtt, no :frowning:

Can I do something about it? Sorry for my knowledge of node-red.


Change the debug node to display the ‘complete msg object’ and then you will be able to see what msg.topic is and verify it is what you think it should be.

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