# String to json object conversion doesnt work

**URL:** <https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795>\
**Category:** General\
**Created:** [22 January 2024 12:14 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795 "2024-01-22T12:14:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![colin0031](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin0031/32/85027_2.png) [@colin0031](https://discourse.nodered.org/u/colin0031)\
**Post date:** [22 January 2024 12:14 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/1 "2024-01-22T12:14:29Z")

</div>

I am listening to a device with TCP request node and I get the information in string as shown in the attachment(1). how to convert it to json object?  
And I get an error converting to json object using json node as shown in attachment(2)

 ![string](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/07bd0c07cd9b67190ad815064bfee7a4e1a566af.jpeg)

 ![json error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/818073786ccf8fd267eef9f2e919a1a22fb9ba2d.jpeg)

---

<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:** [22 January 2024 12:18 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/2 "2024-01-22T12:18:34Z")

</div>

The JSON node converts a JSON string to an Javascript object, or reverse. Your string from the TCP node is a string not a JSON string.

---

<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:** [22 January 2024 12:30 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/3 "2024-01-22T12:30:45Z")

</div>

What is the sending device? Perhaps its format is documented / some obscure protocol format?

Can the device be configured (or updated) to send valid JSON or some other well formed/structured data (XML/YAML/CSV etc)?

If not, then manual parsing in a function node will be possible

---

<div class="post-metadata">

**Author:** ![colin0031](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin0031/32/85027_2.png) [@colin0031](https://discourse.nodered.org/u/colin0031)\
**Post date:** [22 January 2024 12:31 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/4 "2024-01-22T12:31:24Z")

</div>

understood thanks.

---

<div class="post-metadata">

**Author:** ![colin0031](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin0031/32/85027_2.png) [@colin0031](https://discourse.nodered.org/u/colin0031)\
**Post date:** [22 January 2024 12:38 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/5 "2024-01-22T12:38:18Z")

</div>

The device is a sick inspector camera. There are some options to configure output, however I dont see any option to set output format to json object.

I will try those. Thanks.

 ![ethernet_out](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90bc88bef5c72c68de4791c873ee4c1a46a4c1c1.jpeg)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [22 January 2024 12:42 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/6 "2024-01-22T12:42:58Z")

</div>

To me - that looks as if you can create any format you wish in the format string editor box?  
and just use the place holders where you want the data?

Example to submit it as a JSON string:

```auto
{"image_number":<IMAGE_NUMBER/>,"found_blobs":<FOUND_BLOBS/>}

```

---

<div class="post-metadata">

**Author:** ![colin0031](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin0031/32/85027_2.png) [@colin0031](https://discourse.nodered.org/u/colin0031)\
**Post date:** [22 January 2024 12:59 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/7 "2024-01-22T12:59:29Z")

</div>

Super. It works, also started getting messages in node red as json object.

![solution](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fa34edd87051faf7605216d364e4b6626e66f804.jpeg)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 January 2024 14:30 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/8 "2024-01-22T14:30:08Z")

</div>

> [@marcus-j-davies](#):
>
> `>,"found_blobs":<FOUND_BLOBS/>}`

As FOUND\_BLOBS (and POSITION\_(X,Y) ) look more like a string you may need more quotes around it eg `>,"found_blobs":"<FOUND_BLOBS/>"}`

---

<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:** [5 February 2024 14:30 UTC](https://discourse.nodered.org/t/string-to-json-object-conversion-doesnt-work/84795/9 "2024-02-05T14:30:33Z")

</div>

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