# Json split question (mqtt)

**URL:** <https://discourse.nodered.org/t/json-split-question-mqtt/42430>\
**Category:** General\
**Created:** [10 March 2021 20:00 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430 "2021-03-10T20:00:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [10 March 2021 20:00 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/1 "2021-03-10T20:00:36Z")

</div>

I am receiving the following json from a Firebase database:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/ded87eb3912fafa8f236170adf531760aa8c90da.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb7070383aa0e27d2eb155f2168b85158c1265a8.png)

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

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

Thanks!

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [10 March 2021 20:10 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/2 "2021-03-10T20:10:33Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [10 March 2021 20:32 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/3 "2021-03-10T20:32:10Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b2d59deb9b2fed659f227f6576eacdf1ebdd464.png)

Thank you again!

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [10 March 2021 20:38 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/4 "2021-03-10T20:38:14Z")

</div>

Then you'll need to access the property like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c71000588074ae0dd580c290dc33ad41ddc3c87.png)

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [10 March 2021 20:51 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/5 "2021-03-10T20:51:37Z")

</div>

It worked, hotNipi.

Thank you so much!

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [11 March 2021 17:41 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/6 "2021-03-11T17:41:40Z")

</div>

Hello again

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/394463521f7ee6f0dce7fa677f9fb4893750ae07.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bea8ab59fec534591b64728ff64b077fcb3c58f.png)

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e35982051f538af665df4cb9e24adf9f348c8bc8.png)

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.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f139b7b33995163aa64c2db4820eea2794504c2.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0868ac3b684c7daa8ab08e43f4599717da389537.png)

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

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

Thanks!

---

<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:** [11 March 2021 23:10 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/7 "2021-03-11T23:10:43Z")

</div>

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.

---

<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:** [10 May 2021 23:11 UTC](https://discourse.nodered.org/t/json-split-question-mqtt/42430/8 "2021-05-10T23:11:02Z")

</div>

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