# How to get msg.payload in JSON string

**URL:** <https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373>\
**Category:** General\
**Created:** [2 July 2020 11:25 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373 "2020-07-02T11:25:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikthegamer1242](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@erikthegamer1242](https://discourse.nodered.org/u/erikthegamer1242)\
**Post date:** [2 July 2020 11:25 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/1 "2020-07-02T11:25:04Z")

</div>

Hello, I have no idea how to setup this so I will give you following info an then ask the question:  
My flow:

```auto
[{"id":"a5e85d1d.fd0e4","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"436a058b.7c8ecc","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-PlayPause","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"{\"jsonrpc\": \"2.0\", \"method\": \"Player.PlayPause\", \"params\": { \"playerid\": 1 }, \"id\": 1}","x":1000,"y":120,"wires":[]},{"id":"ad6a47ed.7cb598","type":"kodi-in","z":"a5e85d1d.fd0e4","name":"","controller":"4ec0bcd8.097ba4","x":760,"y":760,"wires":[["bab9e363.11556"]]},{"id":"bab9e363.11556","type":"debug","z":"a5e85d1d.fd0e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":960,"y":760,"wires":[]},{"id":"da651687.eb76d8","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-Stop","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"{\"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \"params\": { \"playerid\": 1 }, \"id\": 1}","x":980,"y":180,"wires":[]},{"id":"71ea23f7.8cd16c","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-Volume","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"{\"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": {\"volume\": payload.number}, \"id\": 1}","x":1150,"y":340,"wires":[]},{"id":"5d127c79.8d81c4","type":"inject","z":"a5e85d1d.fd0e4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": { \"volume\":56}, \"id\": 1}","payloadType":"json","x":450,"y":420,"wires":[["71ea23f7.8cd16c"]]},{"id":"b664f84a.6ea0e8","type":"inject","z":"a5e85d1d.fd0e4","name":"","props":[{"p":"payload.number","v":"23","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":360,"y":240,"wires":[["71ea23f7.8cd16c"]]},{"id":"4ec0bcd8.097ba4","type":"kodi-controller","z":"","name":"","host":"192.168.0.15","port":"9090"}]

```

Fisical look of the flow:

 ![Capture.1PNG](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9ba84adab878d53a7b7cf5239bd229d5b3a61fa.png)  
I am trying to send a volume command to Kodi(the play and stop nodes work) using this command:

```auto
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": {"volume": 84}, "id": 1}

```

And it works, but I can't get it to look like this and work:

```auto
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": {"volume": msg.payload.number}, "id": 1}

```

My inject node:

 ![Capture.2PNG](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee31882de700acacbd36d3e3ec30adbaaa16f99a.png)

I am sorry if I am missing any piece of information if you need something else I will provide.  
Have a nice day 🙂

---

<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:** [2 July 2020 12:14 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/2 "2020-07-02T12:14:48Z")

</div>

Once you have the object defined, you could use a change node to change the value like this

 ![Screen Shot 2020-07-02 at 8.14.28 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b74de6e8d9b1b7fc757d22183de12c0780da3e3.png)

---

<div class="post-metadata">

**Author:** ![erikthegamer1242](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@erikthegamer1242](https://discourse.nodered.org/u/erikthegamer1242)\
**Post date:** [2 July 2020 12:16 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/3 "2020-07-02T12:16:25Z")

</div>

Hello, can you tell me what do you mean by object defined, i nver did that i just injected the command...Sorry for taking your time but i cant quite understand this.

---

<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:** [2 July 2020 12:20 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/4 "2020-07-02T12:20:48Z")

</div>

By the way, welcome to the forum! You will find NR addictive, however there are things to learn.

With that in mind, you should take some time to read about JSON and here is a link that I think will help and is much better than I could explain..  
[https://www.w3schools.com/js/js\_json\_objects.asp](https://www.w3schools.com/js/js_json_objects.asp)

---

<div class="post-metadata">

**Author:** ![erikthegamer1242](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@erikthegamer1242](https://discourse.nodered.org/u/erikthegamer1242)\
**Post date:** [2 July 2020 12:22 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/5 "2020-07-02T12:22:11Z")

</div>

Ok thanks for the help, now that i think about it, can i get a copy of your flow or did you just screenshot this node?

---

<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:** [2 July 2020 12:24 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/6 "2020-07-02T12:24:53Z")

</div>

Just add a `change` node after your `inject` node and set it up the way I did.

---

<div class="post-metadata">

**Author:** ![erikthegamer1242](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@erikthegamer1242](https://discourse.nodered.org/u/erikthegamer1242)\
**Post date:** [2 July 2020 12:34 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/7 "2020-07-02T12:34:37Z")

</div>

Thank you so much.It worked perfectly.Have a great day sir and thank you for your time. 🙂

---

<div class="post-metadata">

**Author:** ![erikthegamer1242](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@erikthegamer1242](https://discourse.nodered.org/u/erikthegamer1242)\
**Post date:** [2 July 2020 13:13 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/8 "2020-07-02T13:13:10Z")

</div>

Hello so I tried your way and it worked but then I was able to do this a bit simpler and here is my code if anyone many years from now needs it.

```auto
[{"id":"436a058b.7c8ecc","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-PlayPause","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"{\"jsonrpc\": \"2.0\", \"method\": \"Player.PlayPause\", \"params\": { \"playerid\": 1 }, \"id\": 1}","x":1120,"y":120,"wires":[]},{"id":"da651687.eb76d8","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-Stop","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"{\"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \"params\": { \"playerid\": 1 }, \"id\": 1}","x":1100,"y":180,"wires":[]},{"id":"71ea23f7.8cd16c","type":"kodi-out","z":"a5e85d1d.fd0e4","name":"Kodi-Volume","controller":"4ec0bcd8.097ba4","unit_number":"1","output":"1","kodicommand":"","x":1110,"y":260,"wires":[]},{"id":"4ec0bcd8.097ba4","type":"kodi-controller","z":"","name":"","host":"192.168.0.15","port":"9090"}]

```

---

<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:** [16 July 2020 13:13 UTC](https://discourse.nodered.org/t/how-to-get-msg-payload-in-json-string/29373/9 "2020-07-16T13:13:11Z")

</div>

Closed on 16 July 2020 13:13 UTC

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