# Newbie fails with json formula

**URL:** <https://discourse.nodered.org/t/newbie-fails-with-json-formula/16539>\
**Category:** General\
**Created:** [10 October 2019 10:39 UTC](https://discourse.nodered.org/t/newbie-fails-with-json-formula/16539 "2019-10-10T10:39:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soerenh](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@soerenh](https://discourse.nodered.org/u/soerenh)\
**Post date:** [10 October 2019 10:39 UTC](https://discourse.nodered.org/t/newbie-fails-with-json-formula/16539/1 "2019-10-10T10:39:45Z")

</div>

Hello, i've just started with nodered and set up the first routines, flows etc.  
But i have some problems with controlling my lamps.

I use IKEAs Tradfri lamps, which want their brightness value as JSON like {"brightness":255}  
in the UI i have a slide controller which outputs a value from 0 to 255 _I thought also of using a slider from 0 to 100 and later multiplying with 2.55 to achieve the correct value but unsure how to round as the lamp does not understand values with values after a point (sorry i dont know the english term)_

Can someone explain to me how I put a formula behind it, which then converts the incoming numerical value into a JSON object that I can send to the lamp?

BR

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [10 October 2019 10:53 UTC](https://discourse.nodered.org/t/newbie-fails-with-json-formula/16539/2 "2019-10-10T10:53:44Z")

</div>

Several ways to do it - this is one way without having to write code using the template node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/47ea85a0149f1256a94cc9b257f98ced960cd3a6.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/19259740951da1553d000950cf69b5123ffc50cd.png)

```auto
[{"id":"d7fb13a8.b1718","type":"inject","z":"178669c6.ca0c76","name":"","topic":"","payload":"123","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":974,"y":220,"wires":[["dce96616.044898"]]},{"id":"dce96616.044898","type":"template","z":"178669c6.ca0c76","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"brightness\": {{payload}} }","output":"json","x":1132,"y":220,"wires":[["6794f9ec.115fb8"]]},{"id":"6794f9ec.115fb8","type":"debug","z":"178669c6.ca0c76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1360,"y":220,"wires":[]},{"id":"4df70225.813d1c","type":"inject","z":"178669c6.ca0c76","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":974,"y":264,"wires":[["dce96616.044898"]]}]

```

---

<div class="post-metadata">

**Author:** ![soerenh](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@soerenh](https://discourse.nodered.org/u/soerenh)\
**Post date:** [10 October 2019 11:06 UTC](https://discourse.nodered.org/t/newbie-fails-with-json-formula/16539/3 "2019-10-10T11:06:48Z")

</div>

Thank you very much @cymplecy

Added it and it works just fine. thanks again!
