# How to use JSON node

**URL:** <https://discourse.nodered.org/t/how-to-use-json-node/77556>\
**Category:** General\
**Created:** [14 April 2023 06:32 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556 "2023-04-14T06:32:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoldD](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@GoldD](https://discourse.nodered.org/u/GoldD)\
**Post date:** [14 April 2023 06:32 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556/1 "2023-04-14T06:32:36Z")

</div>

I want to send PLC data to NODE-RED through an IOT gateway so that I can control something as simple as a switch, generate the data value as JSON, and send it to the connected node. (Like a redis node)  
I'm wondering where to connect the JSON node.

Can we connect to the function node right after the switch node, make msg.payload a global variable, and connect to the json node?

If I connect a redis node behind a json node to send data, will it be sent as json?  
Let me know if I'm wrong or need to be careful.

I'm sorry for my English

---

<div class="post-metadata">

**Author:** ![GoldD](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@GoldD](https://discourse.nodered.org/u/GoldD)\
**Post date:** [14 April 2023 06:33 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556/2 "2023-04-14T06:33:51Z")

</div>

![noname](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/854651ab32eae1ad8b786059e937e110e6c90f2c.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [14 April 2023 07:15 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556/3 "2023-04-14T07:15:39Z")

</div>

How are sending the data to/through the IOT gateway? MQTT?

I can't see any MQTT nodes.

The `JSON` node is sort of used to construct a JSON _message_. (Or ~~decode~~ deconstruct one).

I am guessing the _input_ from your IOT is where the `inject` node is?

You mention a _switch_ you want to _control_.  
The terms used are not clear.  
So you mean the `switch` node I can see or are you calling the `gate` node a _switch_?

So depending on HOW you are sending the messages you may not need one.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 April 2023 08:41 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556/4 "2023-04-14T08:41:11Z")

</div>

> [@GoldD](#):
>
> If I connect a redis node behind a json node to send data, will it be sent as json?

I believe that REDIS is a key/value database. As such, it will only be able to store a simple value as text unless you use an extension to REDIS which I'm guessing the REDIS node would not support?

To store as text, assuming you have the data as a JavaScript object on msg.payload, simply send it through a JSON node before sending to REDIS.

---

<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:** [13 June 2023 08:41 UTC](https://discourse.nodered.org/t/how-to-use-json-node/77556/5 "2023-06-13T08:41:55Z")

</div>

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