How to get msg.payload in JSON string

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

[{"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:


I am trying to send a volume command to Kodi(the play and stop nodes work) using this command:

{"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:

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

My inject node:

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

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

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.

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

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?

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

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

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.

[{"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"}]
1 Like

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