# Newbi needs help with a string

**URL:** <https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335>\
**Category:** General\
**Created:** [22 April 2020 21:58 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335 "2020-04-22T21:58:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucaspr](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lucaspr](https://discourse.nodered.org/u/lucaspr)\
**Post date:** [22 April 2020 21:58 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/1 "2020-04-22T21:58:15Z")

</div>

Hi,  
Please bear with me, I'm a total stranger with this. I cannot seem to find my answer with good old google.

I'm trying to change the string from my fronius inverter to something that Domoticz is willing to understand, so a json string.

Here is what I start with:

```auto
{"DAY_ENERGY":{"Unit":"Wh","Value":40110},"DeviceStatus":{"ErrorCode":0,"LEDColor":2,"LEDState":0,"MgmtTimerRemainingTime":-1,"StateToReset":false,"StatusCode":7},"FAC":{"Unit":"Hz","Value":49.99},"IAC":{"Unit":"A","Value":0.22},"IDC":{"Unit":"A","Value":0.24},"PAC":{"Unit":"W","Value":41},"TOTAL_ENERGY":{"Unit":"Wh","Value":6892709.5},"UAC":{"Unit":"V","Value":229.9},"UDC":{"Unit":"V","Value":297.8},"YEAR_ENERGY":{"Unit":"Wh","Value":1605788.38}}

```

That is what comes out of the fronius-node. Now I am interested in a few values.

ENERGY\_DAY, PAC, YEAR\_ENERGY and TOTAL\_ENERGY. So I started filtering out values with msg.payload[0] (for the ENERGY\_DAY), msg.payload[6] (PAC), msg.payload[7] (TOTAL) and msg.payload[10] (YEAR) energy

But I found that msg.payload[0] isn't ENERGY\_DAY and all the values (like msg.payload[0].Value for today's total) but '{' .

I know I'm missing something, starting with knowledge to all this. Who is willing to help me? I'm clueless in this one. I'm willing to share my project if I can get it to work. Which I think someone has already done and I'm inventing the wheel again. But I can't find it. And yes there is a plugin for domoticz to work with the fronius inverter, but it is horrible unstable in my setup. So I thought let's go with node red...

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [23 April 2020 00:10 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/2 "2020-04-23T00:10:38Z")

</div>

Have a look in the debug window on the right hand side - it provides an object browser so you can see exactly what the full "path" is to each node in the string

So bring in your value, and output to a debug node - then drill down in the debug window and see what you get

Post up some screenshots of this and your results

Craig

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [23 April 2020 04:17 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/3 "2020-04-23T04:17:04Z")

</div>

to expand on what @craigcurtin said. You are receiving a JSON string it looks like. This is a string representation of a Javascript object. First thing in question is did you already parse it to javascript object?  
If it comes out of the first node in exactly this format you posted above you will have to do this to be able to work with it.  
You can simply use the JSON node that you can find in the Palette on the left to do this.  
Secondly you have a javascript object of type object but msg.payload[0] is a way to access a property of an object of type array.  
So have a look at [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)  
as this will give you all the information needed on what object types their are and understanding what you see in the debug window and how to work with it.

Johannes

---

<div class="post-metadata">

**Author:** ![lucaspr](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lucaspr](https://discourse.nodered.org/u/lucaspr)\
**Post date:** [23 April 2020 06:30 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/4 "2020-04-23T06:30:38Z")

</div>

Thank you guys for the info.

I knew I had something wrong with the msg.payload[0] and [1]. But I get it , I have to get the JSON into an array to get that working. Makes sense now, feeling a bit stupid 🙂 , but everybody has strong points and weak points.

These are the nodes and debug window:

 ![screen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1fca28dfd6f2fa06d26ee2b306cfc310ded50fd.jpeg)

The string as I posted it is from the debug window attached to fronius-control-in. Hope you can help! Like to learn this (a bit).

I installed the fronius-control-in node in the settings.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [23 April 2020 06:46 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/5 "2020-04-23T06:46:59Z")

</div>

can you show us a picture of what comes straight out of the fronius node when you connect a debug to it? Maybe you dont need the json node.  
And think again, its not an array. There is a difference between an array and an object. You will have to work with object keys and not array indexes. Its all in the link I posted to the documentation.

Edit: just to clarify is the output we see in the debug window from the debug attached to the json node or is this from when the debug was connected directly to the fronius node?

---

<div class="post-metadata">

**Author:** ![lucaspr](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lucaspr](https://discourse.nodered.org/u/lucaspr)\
**Post date:** [23 April 2020 07:17 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/6 "2020-04-23T07:17:15Z")

</div>

This is the output then in the debug window.  
 ![debug-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d579e8685097fa040b277615800646dd847047f.png)

and expanded:

 ![screen3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b13d0314e2eaea8c49082251304d0bd05ace218.jpeg)

I'm sorry, my thoughts on the msg.payload[0] were in general. Not for this string, this one first needs to be json to work with it.

To the right is where I click to see the debug messages. Do correct me if I'm wrong.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [23 April 2020 07:34 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/7 "2020-04-23T07:34:41Z")

</div>

No this is already an object you can work with no json node needed. Please read the section on understanding the structure of a message here [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)  
When you have done this you should have all the tools to figure it out.  
But to repeat it:  
You have a object and not an array your working with. So `msg.payload[0]` cant work as its an array reference. You will have to use something like `msg.payload.DAY_ENERGY`. Objects have keys and arrays have indexes.  
If you hover over one of those in the debug tab like `DAY_ENERGY` it will give you little icons on the side and one of them will give you this path.  
This is all explained in the documentation i posted the link to including a link to further information about javascript object types [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data\_structures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures).

---

<div class="post-metadata">

**Author:** ![lucaspr](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@lucaspr](https://discourse.nodered.org/u/lucaspr)\
**Post date:** [23 April 2020 08:11 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/8 "2020-04-23T08:11:38Z")

</div>

Thanx for pointing me in the right direction! I will do that.

Thank you so much! Got it working with a change node. Now I can add the needed info into the original object! So simple....

---

<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:** [22 June 2020 08:11 UTC](https://discourse.nodered.org/t/newbi-needs-help-with-a-string/25335/9 "2020-06-22T08:11:43Z")

</div>

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