# Help substituting value

**URL:** <https://discourse.nodered.org/t/help-substituting-value/6354>\
**Category:** General\
**Created:** [3 January 2019 15:33 UTC](https://discourse.nodered.org/t/help-substituting-value/6354 "2019-01-03T15:33:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [3 January 2019 15:33 UTC](https://discourse.nodered.org/t/help-substituting-value/6354/1 "2019-01-03T15:33:02Z")

</div>

I have a function node with the following :

msg.payload='{"state":"ON","brightness":250,"color\_temp":250,"bulb\_mode":"white","color":{"r":255,"g":255,"b":255}}';  
return msg;

It works fine but I am totally stumped, how do I substitute "brightness":250 to "brightness": 'a value' contained in the incoming msg payload ? like if I inject 100 into the function node the output should = "brightness":100

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.nodered.org/u/Martin)\
**Post date:** [3 January 2019 15:39 UTC](https://discourse.nodered.org/t/help-substituting-value/6354/2 "2019-01-03T15:39:12Z")

</div>

Heeey, i think you should try something like this:

var inconming = msg.payload;  
msg.payload='{"state":"ON","brightness":incoming,"color\_temp":250,"bulb\_mode":"white","color":{"r":255,"g":255,"b":255}}';  
return msg;

pd: taking msg.payload as an integer, otherwise you must use parseInt()  
Regards!.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [3 January 2019 16:39 UTC](https://discourse.nodered.org/t/help-substituting-value/6354/3 "2019-01-03T16:39:05Z")

</div>

> [@Dave](#):
>
> msg.payload='{"state":"ON","brightness":250,"color\_temp":250,"bulb\_mode":"white","color":{"r":255,"g":255,"b":255}}';  
> return msg;

If your intent is to return a JSON **string** then you will have to concatenate the incoming payload into the middle of the string using the JS concatenate operator `+` like so:

```auto
msg.payload = '{"state":"ON","brightness":' + msg.payload + ', "color_temp": 250, "bulb_mode": "white", "color": { "r": 255, "g": 255, "b": 255 } }';

```

which would more simply be done with a `template` node, configured like so:

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

On the other hand, if your intention is to create a payload **object** then the JS syntax is:

```auto
msg.payload = {
    "state": "ON",
    "brightness": +msg.payload,
    "color_temp": 250,
    "bulb_mode": "white",
    "color": {
        "r": 255,
        "g": 255,
        "b": 255
    }
};
return msg;

```

which you can also accomplish by checking the "Output as Parsed JSON" on the `change` node above.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [3 January 2019 17:15 UTC](https://discourse.nodered.org/t/help-substituting-value/6354/4 "2019-01-03T17:15:34Z")

</div>

Thanks **shrickus** your first solution works perfectly for me (I swear I tried this solution about 4 hours ago but obviously I must have made some mistake) anyway I can now move on thanks again.
