# JSON send to TCP

**URL:** https://discourse.nodered.org/t/json-send-to-tcp/65141
**Category:** General
**Created:** [15 July 2022 11:03 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141 "2022-07-15T11:03:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wiwan-wijoyo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wiwan-wijoyo/32/48198_2.png) [@wiwan-wijoyo](https://discourse.nodered.org/u/wiwan-wijoyo)
#### Post date: [15 July 2022 11:03 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/1 "2022-07-15T11:03:35Z")

</div>

this is an example of sending a command via terminal the result OK  
{"CommuniqueType":"ReadRequest","Header":{"Url":"/server/status/ping"}}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba1cb8afe0dfabc9dee9570b756df77785832b4c.png)

I tried to connect via TCP and send the command, but the result is an error.

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c5dec12830e26b5f9ab3459152259193c207468.png)

if I check from terminal there is an error here  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3be7bbf527648eb2a50ba47909a7e11889ba103a.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e1e6e99fd15ea65891c95809a5e8dcaae5df497.png)

I hope someone can help me.

---

<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: [15 July 2022 11:24 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/2 "2022-07-15T11:24:10Z")

</div>

As a first test, what happens if you enter `{"CommuniqueType":"ReadRequest","Header":{"Url":"/server/status/ping"}}` into an inject node (as a `str` **not** `json`) and connect that to the TCP request,

e.g.

1. INJECT (set payload to string `{"CommuniqueType":"ReadRequest","Header":{"Url":"/server/status/ping"}}` ) →
2. TCP request →
3. Debug

  

As I see it, the JSON node is formatting the JSON with spaces and newlines  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4b85b136d7dd02c341485418925ad89ab29d8a1.png) and I suspect the `newline`s are causing the other end to think that is the end of transmission.

Additionally, how is the TCP node set up (show me please)

---

<div class="post-metadata">

### Author: ![wiwan-wijoyo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wiwan-wijoyo/32/48198_2.png) [@wiwan-wijoyo](https://discourse.nodered.org/u/wiwan-wijoyo)
#### Post date: [15 July 2022 15:18 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/3 "2022-07-15T15:18:51Z")

</div>

I have tried with "inject node" but it doesn't output any result in debug.

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

this my TCP setup  
[flows.json](https://discourse.nodered.org/uploads/short-url/4oyjYVDUUo4SFhpEJLlC3YwAS1A.json) (2.9 KB)

---

<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: [15 July 2022 15:21 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/4 "2022-07-15T15:21:17Z")

</div>

Try adding a newline - use a function node between inject and TCP...

```auto
msg.payload += "\n"
return msg

```

---

<div class="post-metadata">

### Author: ![wiwan-wijoyo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wiwan-wijoyo/32/48198_2.png) [@wiwan-wijoyo](https://discourse.nodered.org/u/wiwan-wijoyo)
#### Post date: [15 July 2022 15:28 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/5 "2022-07-15T15:28:45Z")

</div>

working well...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73b0dfd8d2a77de63b25aa7cae4dd3e198c9a4c0.png)

thank's steve...

---

<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: [29 July 2022 15:28 UTC](https://discourse.nodered.org/t/json-send-to-tcp/65141/6 "2022-07-29T15:28:53Z")

</div>

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