# Msg String to object

**URL:** <https://discourse.nodered.org/t/msg-string-to-object/54081>\
**Category:** General\
**Created:** [21 November 2021 23:00 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081 "2021-11-21T23:00:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helix78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helix78/32/51415_2.png) [@Helix78](https://discourse.nodered.org/u/Helix78)\
**Post date:** [21 November 2021 23:00 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/1 "2021-11-21T23:00:40Z")

</div>

I execute a poweshell script which produces a string output.

msg : string[4]  
"307↵"

I did not manage to parse it to a useable object.  
It seems I cannot access the plain string which comes with msg.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 November 2021 00:12 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/2 "2021-11-22T00:12:25Z")

</div>

Hi @Helix78,

Welcome to the forum.

Which node exactly (node-red-contrib-???) is giving you that message?

---

<div class="post-metadata">

**Author:** ![Helix78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helix78/32/51415_2.png) [@Helix78](https://discourse.nodered.org/u/Helix78)\
**Post date:** [22 November 2021 07:15 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/3 "2021-11-22T07:15:12Z")

</div>

The node is node-red-contrib-powershell : powershell

There a PS1 is executed calling a js-file  
node generic.js  
console.log(307)

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [22 November 2021 09:21 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/4 "2021-11-22T09:21:42Z")

</div>

Normally, outputs are put into msg.payload (msg itself is the whole message object)

Can you connect a debug node to the output and show us what it displays?

---

<div class="post-metadata">

**Author:** ![Helix78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helix78/32/51415_2.png) [@Helix78](https://discourse.nodered.org/u/Helix78)\
**Post date:** [22 November 2021 09:42 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/5 "2021-11-22T09:42:53Z")

</div>

The output is generated by node-red-contrib-powershell. I tried to format the output as a js object but it was still treated as a string.

This is the output of a debug node:

msg : string[4]  
"307↵"

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 November 2021 09:43 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/6 "2021-11-22T09:43:07Z")

</div>

> [@Helix78](#):
>
> node-red-contrib-powershell

Looking at that node's code, it is simply broken. It is sending the raw String output from the powershell command as the whole message, where as it should be setting it as a property of a message object.

It's code is _almost_ right:

```auto
  .then(output => {
     msg.payload = output;
     this.send([output, null]);
})

```

It does set the message property, but then sends `output` instead of `msg`.

Unfortunately the node has no github repository associated with it and it hasn't been updated in 3 years - so despite it being a simple fix to apply, there doesn't seem to be a route to doing that via this module.

I would recommend not using this node.

---

<div class="post-metadata">

**Author:** ![Helix78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helix78/32/51415_2.png) [@Helix78](https://discourse.nodered.org/u/Helix78)\
**Post date:** [22 November 2021 09:44 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/7 "2021-11-22T09:44:05Z")

</div>

ok thanks. is there any alternative node I can use?

EDIT: I managed to call the node js by exec node. Now it works!

---

<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:** [21 January 2022 09:44 UTC](https://discourse.nodered.org/t/msg-string-to-object/54081/8 "2022-01-21T09:44:33Z")

</div>

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