# Can I pass a JSON message in a change node to a template node to be spoken?

**URL:** <https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266>\
**Category:** General\
**Created:** [23 October 2023 00:29 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266 "2023-10-23T00:29:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappyjim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nappyjim/32/34077_2.png) [@nappyjim](https://discourse.nodered.org/u/nappyjim)\
**Post date:** [23 October 2023 00:29 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/1 "2023-10-23T00:29:48Z")

</div>

I've taken out all unncessary parts of the flow, just FYI.

I know its currently wrong; but I am looking for how to do it, if possible. In my change node, I would like the message it passes along to be spoken to be dynamically changed based on its input.

So in my example, I set msg.carrier to ups. I would then like the change node to input that into its message that it passes to the TTS template node. So that in the end, my speaker says "A package from UPS has been delivered".

```auto
[{"id":"ebd69f4bccf807e7","type":"tab","label":"Mail","disabled":false,"info":"","env":[]},{"id":"8e97a41daf1fb970","type":"alexa-remote-routine","z":"ebd69f4bccf807e7","name":"Speak: msg.payload","account":"f0ce5fbc.18734","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"jsonata","value":"payload"},"volume":{"type":"num","value":"20"},"mode":"set","devices":["G6G0XG11030205CT"]}},"x":910,"y":390,"wires":[[]]},{"id":"22a918f799ca58e5","type":"template","z":"ebd69f4bccf807e7","name":"TTS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<speak>\n<voice name= \"{{voice}}\" >\n{{message}} \n</voice>\t\n</speak> ","output":"str","x":715,"y":390,"wires":[["8e97a41daf1fb970"]]},{"id":"dc6284b3ae4371fc","type":"inject","z":"ebd69f4bccf807e7","name":"Set carrier UPS","props":[{"p":"carrier","v":"ups","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":215,"y":390,"wires":[["7ee9cc44eb29febd"]]},{"id":"7ee9cc44eb29febd","type":"change","z":"ebd69f4bccf807e7","name":"Message: All packages delivered","rules":[{"t":"set","p":"message","pt":"msg","to":"A package from {{carrier}} has been delivered.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":390,"wires":[["22a918f799ca58e5"]]},{"id":"f0ce5fbc.18734","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.86.215","proxyPort":"3456","cookieFile":"Auth","refreshInterval":"15","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.com","acceptLanguage":"en-US","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

```

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

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [23 October 2023 06:08 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/2 "2023-10-23T06:08:52Z")

</div>

Try replacing the 'change' node with a 'function' that has the following code in it.

```auto
let text = "A package from "+msg.carrier+ " has been delivered";
msg = {message:text};
return msg;

```

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [23 October 2023 06:15 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/3 "2023-10-23T06:15:12Z")

</div>

You're almost there! 👍

In the `change` node, set the new values format to "expression" (depicted by the 'J') and then use a bit of [JSONata](https://jsonata.org/) to put your message together, e.g.:

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 October 2023 06:16 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/4 "2023-10-23T06:16:17Z")

</div>

@nappyjim This example should work for you.

```auto
[{"id":"dc6284b3ae4371fc","type":"inject","z":"ebd69f4bccf807e7","name":"Set carrier UPS","props":[{"p":"carrier","v":"u p s","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":300,"wires":[["ae44a490487c5750"]]},{"id":"ae44a490487c5750","type":"change","z":"ebd69f4bccf807e7","name":"","rules":[{"t":"set","p":"voice","pt":"msg","to":"Emma","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":240,"wires":[["22a918f799ca58e5"]]},{"id":"22a918f799ca58e5","type":"template","z":"ebd69f4bccf807e7","name":"TTS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<speak>\n<voice name= \"{{voice}}\" >\nA package from {{carrier}} has been delivered\n</voice>\t\n</speak> ","output":"str","x":310,"y":300,"wires":[["8e97a41daf1fb970"]]},{"id":"8e97a41daf1fb970","type":"alexa-remote-routine","z":"ebd69f4bccf807e7","name":"Speak: msg.payload","account":"c8738129.d902c","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"payload"},"volume":{"type":"num","value":"20"},"mode":"set","devices":["G090LF1182850C6D"]}},"x":490,"y":280,"wires":[["5a2f5116933c43e5"]]},{"id":"5a2f5116933c43e5","type":"debug","z":"ebd69f4bccf807e7","name":"debug 347","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":220,"wires":[]},{"id":"c8738129.d902c","type":"alexa-remote-account","name":"alexa remote 2","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"14","alexaServiceHost":"layla.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-GB","onKeywordInLanguage":"","userAgent":"","useWsMqtt":"on","autoInit":"off"}]

```

Using SSML [Speech Synthesis Markup Language (SSML) Reference | Alexa Skills Kit](https://developer.amazon.com/en-US/docs/alexa/custom-skills/speech-synthesis-markup-language-ssml-reference.html#about-ssml)

@ralphwetzel Sorry used the wrong reply button.

---

<div class="post-metadata">

**Author:** ![nappyjim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nappyjim/32/34077_2.png) [@nappyjim](https://discourse.nodered.org/u/nappyjim)\
**Post date:** [24 October 2023 01:59 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/5 "2023-10-24T01:59:40Z")

</div>

Thank you guys for all the suggestions, I tried all and they all seem to work. Now I just gotta see which way works the best when incorporated into the full flow

---

<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:** [7 November 2023 02:00 UTC](https://discourse.nodered.org/t/can-i-pass-a-json-message-in-a-change-node-to-a-template-node-to-be-spoken/82266/6 "2023-11-07T02:00:28Z")

</div>

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