# Help parsing nested JSON data

**URL:** <https://discourse.nodered.org/t/help-parsing-nested-json-data/14586>\
**Category:** General\
**Created:** [21 August 2019 07:50 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586 "2019-08-21T07:50:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lineal](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lineal](https://discourse.nodered.org/u/lineal)\
**Post date:** [21 August 2019 07:50 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/1 "2019-08-21T07:50:19Z")

</div>

Hi,

I intend to monitor data from a PLC in the form of a bar graph. I am able to get the JSON data, but I'm new to node red and I'm having trouble extracting data from JSON in msg.payload.

My JSON looks something like this:

```auto
{
   "timestamp":1566387382870,
   "values":[
      {
         "instanceId":0,
         "resourceId":5700,
         "datatype":"Float",
         "value":500,
         "objectId":3300
      }
   ]
}

```

At the moment, I am trying to display only 'value' of 500.

I've been looking though these forums and the documentation and so far, I have been able to show 'timestamp', and all the content of 'values', but I can't figure out a way to display only 'value'.

This is what I have so far in my function:

```auto
var obj = JSON.parse(msg.payload); // Stores JSON text as an object.
var valuee = JSON.stringify(obj.values);
msg.payload = valuee;
return msg;

```

Sorry if the answer is simple, I'm not very familiar with node-red yet, so if somebody could help me out, I would be grateful. Thanks!

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 07:55 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/2 "2019-08-21T07:55:21Z")

</div>

You don't say where you are getting the data from.  
If it is a JSON string then you can convert it to a javascript object ( which is what you manipulate in Node-RED using the JSON node (or the first line of your function)

But often the "input" nodes are sensible enough to output a javascript object for you.  
Add a debug and you should see it will say if it is a string or an object.

This page in the docs [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages) explains how to then use the debug panel to find the correct path to any bit of data

---

<div class="post-metadata">

**Author:** ![lineal](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lineal](https://discourse.nodered.org/u/lineal)\
**Post date:** [21 August 2019 08:20 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/3 "2019-08-21T08:20:01Z")

</div>

I'm not sure how to explain...I'm using something called LoopEdge, I connected my PLC through that, and I have a datahub, which is where the data is coming from.

Here is my flow, if it helps explain at all.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f5e45580db9e7b8d1bf6f025bc6098c9300c720c.png)

Thank you for that link, I'll read it and try to do what you suggested.

---

<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:** [21 August 2019 08:28 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/4 "2019-08-21T08:28:44Z")

</div>

Sorry, I realise this is off-topic, but I have to ask... why is your Function node a round circle? Where did you get your Node-RED from?

---

<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:** [21 August 2019 08:35 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/5 "2019-08-21T08:35:49Z")

</div>

> [@lineal](#):
>
> { "timestamp":1566387382870, "values":[{ "instanceId":0, "resourceId":5700, "datatype":"Float", "value":500, "objectId":3300 }] }

Assuming it is attached to the msg payload:

```
msg.payload.values[0].value

```

The thing that catches a lot of people out is the fact that the inner `values` object is wrapped in an array which you have to deal with (`[0]`) before you can access the data.

---

<div class="post-metadata">

**Author:** ![lineal](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lineal](https://discourse.nodered.org/u/lineal)\
**Post date:** [22 August 2019 05:27 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/6 "2019-08-22T05:27:11Z")

</div>

I'm using something called LoopEdge with LoopFlows. Inside LoopFlows there is a way to add the node-red library. I guess this function node is part of LoopFlows rather than node-RED, but I believe (and hope) it works in the same way. Maybe I'm totally wrong... (I was suddenly given a project and I don't really have any idea about LoopEdge or node-RED 😅 I'm trying to learn but I'm limited for time, so I appreciate this forum...)

---

<div class="post-metadata">

**Author:** ![lineal](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lineal](https://discourse.nodered.org/u/lineal)\
**Post date:** [22 August 2019 05:35 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/7 "2019-08-22T05:35:23Z")

</div>

Thank you! This solved my problem. I appreciate it a lot!

---

<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 August 2019 06:50 UTC](https://discourse.nodered.org/t/help-parsing-nested-json-data/14586/8 "2019-08-22T06:50:29Z")

</div>

Looks like a heavily modified version of an early node red...

[https://docs.litmusautomation.com/plugins/servlet/mobile?contentId=10000254#content/view/10000254](https://docs.litmusautomation.com/plugins/servlet/mobile?contentId=10000254#content/view/10000254)
