# How to pass payload to JSON

**URL:** https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535
**Category:** General
**Created:** [14 February 2024 18:10 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535 "2024-02-14T18:10:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)
#### Post date: [14 February 2024 18:10 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/1 "2024-02-14T18:10:04Z")

</div>

I think this might be something easy. I have a payload coming in as a number and using a change node to change it to JSON. Been playing around with quotes and curly brackets, but it's just pulling the text in on my debug. Any ideas what i'm doing wrong?

```auto
{
    "method": "setPilot",
    "params": {
        "dimming": "{{payload}}"
    }
}

```

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

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

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [14 February 2024 18:23 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/2 "2024-02-14T18:23:18Z")

</div>

> [@CAL37](#):
>
> ```auto
> {
> "method": "setPilot",
> "params": {
> "dimming": "{{payload}}"
> }
> }
> 
> ```

That would work in a template node (though you'd probably not want the quotes if you want it to be a number)

If you want to do it in a change node, then use JSONata OR copy the payload to a temporary msg property in the first row, set the payload to your format in the 2nd row then finally, in the 3rd row, set `payload.params.dimming` to the value of the \_temp value from row 1.

---

<div class="post-metadata">

### Author: ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)
#### Post date: [14 February 2024 18:58 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/3 "2024-02-14T18:58:22Z")

</div>

@Steve-Mcl appreciate it, I was able to use the template node and use the JSON node to convert it. I'm not too familiar with how to do the second option, but hope to get there eventually.

---

<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: [14 February 2024 19:28 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/4 "2024-02-14T19:28:05Z")

</div>

No need for JSON node the template node can output a JSON string, or if you select output `parsed JSON` a Javascript object.

p.s share your solution so others can see the solutuion, export you working example flow and paste it, then your solution can help others.

---

<div class="post-metadata">

### Author: ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)
#### Post date: [14 February 2024 20:22 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/5 "2024-02-14T20:22:10Z")

</div>

@E1cid I see that option and that's great! 1 less node not to have to use.

Here is my flow. It's still work in progress, but have a virtual light/bulb (Wiz) that I'm passing commands to dim/color/on and off.

```auto
[
    {
        "id": "77ccb529164df155",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "766a83b7d19b8b74",
        "type": "alexa-smart-home-v3",
        "z": "77ccb529164df155",
        "conf": "c90ca88c.3bab68",
        "device": "60075",
        "acknowledge": true,
        "name": "Light Test",
        "topic": "",
        "x": 320,
        "y": 380,
        "wires": [
            [
                "7f36d38888653298",
                "628d0399d643e52f",
                "c31cacb32c23489e"
            ]
        ]
    },
    {
        "id": "252442223f8aab14",
        "type": "udp out",
        "z": "77ccb529164df155",
        "name": "Send",
        "addr": "",
        "iface": "",
        "port": "38899",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 1530,
        "y": 360,
        "wires": []
    },
    {
        "id": "3628125aa8a9575e",
        "type": "json",
        "z": "77ccb529164df155",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 1350,
        "y": 360,
        "wires": [
            [
                "252442223f8aab14"
            ]
        ]
    },
    {
        "id": "f92fc7811dde1c42",
        "type": "change",
        "z": "77ccb529164df155",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "ip",
                "pt": "msg",
                "to": "192.168.107.74",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1150,
        "y": 360,
        "wires": [
            [
                "3628125aa8a9575e"
            ]
        ]
    },
    {
        "id": "c6d669a573d7e897",
        "type": "change",
        "z": "77ccb529164df155",
        "name": "on",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{ \"method\": \"setPilot\", \"params\": { \"state\": true } }",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 770,
        "y": 300,
        "wires": [
            [
                "f92fc7811dde1c42"
            ]
        ]
    },
    {
        "id": "7f36d38888653298",
        "type": "switch",
        "z": "77ccb529164df155",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "ON",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "OFF",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 550,
        "y": 380,
        "wires": [
            [
                "c6d669a573d7e897"
            ],
            [
                "c1651469f5119aeb"
            ],
            [
                "12dc22329943da81"
            ]
        ]
    },
    {
        "id": "c1651469f5119aeb",
        "type": "change",
        "z": "77ccb529164df155",
        "name": "off",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"method\":\"setPilot\",\"params\":{\"state\":false}}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 770,
        "y": 380,
        "wires": [
            [
                "f92fc7811dde1c42"
            ]
        ]
    },
    {
        "id": "12dc22329943da81",
        "type": "debug",
        "z": "77ccb529164df155",
        "name": "debug 64",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 440,
        "wires": []
    },
    {
        "id": "628d0399d643e52f",
        "type": "debug",
        "z": "77ccb529164df155",
        "name": "debug 65",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 280,
        "wires": []
    },
    {
        "id": "c31cacb32c23489e",
        "type": "switch",
        "z": "77ccb529164df155",
        "name": "",
        "property": "command",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "SetBrightness",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 530,
        "y": 500,
        "wires": [
            [
                "9f4ebb254bbe4f28"
            ]
        ]
    },
    {
        "id": "9f4ebb254bbe4f28",
        "type": "template",
        "z": "77ccb529164df155",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\"method\":\"setPilot\",\"params\":{\"dimming\":{{payload}}}}\n",
        "output": "json",
        "x": 760,
        "y": 540,
        "wires": [
            [
                "f92fc7811dde1c42"
            ]
        ]
    },
    {
        "id": "c90ca88c.3bab68",
        "type": "alexa-smart-home-v3-conf",
        "username": "allenle37",
        "mqttserver": "mq-red.cb-net.co.uk",
        "webapiurl": "red.cb-net.co.uk",
        "contextName": "memoryOnly"
    }
]

```

---

<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: [28 February 2024 20:22 UTC](https://discourse.nodered.org/t/how-to-pass-payload-to-json/85535/6 "2024-02-28T20:22:33Z")

</div>

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