Format output of array with carriage returns

Hi, I've been banging my head on this without much success.

The output of my payload will be sent to whatsapp. But it lists everything with a comma and I'd like a carriage return.

[{"id":"c2ca69f3dbe80770","type":"api-call-service","z":"5c26fb4772d3c08c","name":"Whatsapp","server":"a0eea9da.0fe1d8","version":3,"debugenabled":false,"service_domain":"notify","service":"whatsapp","entityId":"","data":"{\"message\":\"{{payload.attributes.entities}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":420,"wires":[[]]},{"id":"1f76c24e88ac0bea","type":"inject","z":"5c26fb4772d3c08c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":440,"wires":[["fc6e9e334e49f3d0"]]},{"id":"fc6e9e334e49f3d0","type":"api-current-state","z":"5c26fb4772d3c08c","name":"Unavailablke sensor","server":"a0eea9da.0fe1d8","version":3,"outputs":2,"halt_if":"2","halt_if_type":"str","halt_if_compare":"does_not_include","entity_id":"sensor.unavailable_entities","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":500,"y":440,"wires":[["fc20e36941d596c7","c2ca69f3dbe80770"],[]]},{"id":"fc20e36941d596c7","type":"debug","z":"5c26fb4772d3c08c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":480,"wires":[]},{"id":"a0eea9da.0fe1d8","type":"server","name":"GOOD Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

The output in whatsapp is hard to read, because it's seperated by a comma instead of new line

I'm lacking competence in the functions to change this - I tried several things but they don't work...
My debug info

Any suggesiton please?

I think the HA node allows JSONata
so you could try

{"message": $join($$.payload.attributes.entities, "\n")}

or in a change node before
Set msg.payload.attributes.entities
To JSONata expression $join($$.payload.attributes.entities, "\n")

Hi, thanks, just tested.
this first one results in empty topic
{"message": $join($$.payload.attributes.entities, "\n")}
the tester in nodered returns

Invalid example JSON message:
SyntaxError: Unexpected token $ in JSON at position 12

But... the second one worked :slight_smile: with a change node.

[{"id":"c2ca69f3dbe80770","type":"api-call-service","z":"5c26fb4772d3c08c","name":"Whatsapp","server":"a0eea9da.0fe1d8","version":3,"debugenabled":false,"service_domain":"notify","service":"whatsapp","entityId":"","data":"{\"message\":\"{{payload.attributes.entities}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":760,"y":380,"wires":[[]]},{"id":"1f76c24e88ac0bea","type":"inject","z":"5c26fb4772d3c08c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":440,"wires":[["fc6e9e334e49f3d0"]]},{"id":"fc6e9e334e49f3d0","type":"api-current-state","z":"5c26fb4772d3c08c","name":"Unavailablke sensor","server":"a0eea9da.0fe1d8","version":3,"outputs":2,"halt_if":"2","halt_if_type":"str","halt_if_compare":"does_not_include","entity_id":"sensor.unavailable_entities","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":500,"y":440,"wires":[["80a495f7dd6a26c8"],[]]},{"id":"fc20e36941d596c7","type":"debug","z":"5c26fb4772d3c08c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":420,"wires":[]},{"id":"80a495f7dd6a26c8","type":"change","z":"5c26fb4772d3c08c","name":"Clean","rules":[{"t":"set","p":"msg.payload.attributes.entities","pt":"msg","to":"$join($$.payload.attributes.entities, \"          \")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":380,"wires":[["c2ca69f3dbe80770","fc20e36941d596c7"]]},{"id":"a0eea9da.0fe1d8","type":"server","name":"GOOD Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

Except... that whatsapp api built for Home Assistant - or whatsapp API itself doesn't allow the special character... Lots of discussions online about it - tried different things
and %0a notably but none worked :frowning:
So I resolved myseld to add 5 spaces in your change node instead of the line break and it's at least much better.

Thanks a lot.

you need to set to JSONata not JSON

not sure what whatsapp uses as i don't use it, but you could try html <br>or markup \

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