Help with helping someone - splitting JSON objects

I am helping someone and I am asking here for help. Not because I want the glory of being the one who did it but more to not confuse the person with a lot of people giving their thoughts.
(No offence)

I am not exactly getting it, and may have actually done what they need doing now anyway.
But for the sake of keeping options open, I'm asking.

This is a cut down message.

{"topic":"ATESTEO/Wolfsburg/W16","payload":{"MQTTWert1":"25.1","MQTTWert1name":"T_BoxenLuft","MQTTWert2":"-101","MQTTWert2name":"N_EMA_VL","MQTTWert3":"932","MQTTWert3name":"n_Antrieb","MQTTWert4":"269","MQTTWert4name":"M_Antrieb","Status":"Läuft"},"qos":1,"retain":false,"_topic":"ATESTEO/Wolfsburg/W16","_msgid":"3f4512b0.dc5bee","kColor":"black","vColor":"black","template":"<html>\n<head>\n<style>\ntable.FixedTable\n{\n    table-layout: fixed;\n    border: 0;\n}\n</style>    \n</head>\n<body>\n<table class=\"FixedTable\">\n <tbody>\n  <tr ng-repeat=\"(k,v) in msg.payload\" ng-if=\"k != 'Item'\">\n   <td style=\"width: 250; color:{{msg.kColor}}\">{{k}}</td>\n   <td style=\"text-align:justify; color:{{msg.vColor}}\">{{v}}</td>\n  </tr>\n </tbody>\n</table>\n</body>\n</html>","color":"lime"}

The payload is ..... the part of interest to split.
There are other things which are claimed are needed. Shrug. Dunno. I can't see how/why as the data is ultimately going to a chart node.

The payload has two lines. A name and a value.
It would be nice to split this up so there are (in this case) 4 messages sent out.
Each with a topic of what the name is and a payload of what the value is, and the other stuff which is in the bigger message as themselves.

Yes, this may be futile and the problem is already solved by what I did. But I'm not that arrogant to think I have found the answer this quickly / easily.

Someone - please.

Use a Split node, with the Copy key to... option enabled and configured to set msg.topic:

1 Like

Ok, (second attempt) but I am getting:
Invalid split property: Error: invalid array split length:

I think the split using part is not set correctly. I left the default \n in there. I'm guessing I need to delete it too?

Ok, length. But the message part lengths are not fixed as far as I know/see.

It depends on the data you are passing it.

The example message you shared has msg.payload as an Object. So you can ignore the 'String' and 'Array' options in the Split node and focus on the Object options as I suggested.

Leave all the options in the Split node to their default value, apart from the Copy key option I highlighted.

Sorry. Only about 60 minutes out of bed.

That looks interesting/promising for things.

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