# JSON question, get one value

**URL:** <https://discourse.nodered.org/t/json-question-get-one-value/31499>\
**Category:** General\
**Created:** [12 August 2020 20:39 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499 "2020-08-12T20:39:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [12 August 2020 20:39 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/1 "2020-08-12T20:39:59Z")

</div>

Help extract data from JSON  
I am receiving this JSON string from a Sonoff RF bridge:

```auto
{
   "Time":"2020-08-12T20:55:56",
   "RfReceived":{
      "Sync":12980,
      "Low":410,
      "High":1270,
      "Data":"DD80F2",
      "RfKey":"None"
   }
}

```

I just want the data. (msg.payload = DD80F2).  
When I put this into a function:

```auto
var myData = msg.payload.RfReceived.Data;
msg.payload = myData;
return msg;

```

I get this error:  
TypeError: Cannot read property 'Data' of undefined

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 August 2020 20:57 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/2 "2020-08-12T20:57:28Z")

</div>

Can you feed the input into a debug node and post a screenshot please?  
**[Edit]** If the debug says it is a string then feed it into a JSON node then into your function.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 August 2020 21:25 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/3 "2020-08-12T21:25:15Z")

</div>

Are you sure that that is all contained in msg.payload (so it would be `msg.payload.RfReceived.Data` or might it be outside msg.payload an be `msg.RfReceived.Data`?

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [12 August 2020 21:30 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/4 "2020-08-12T21:30:12Z")

</div>

Thanks for looking at it. This is the whole object:  
`{"topic":"tele/bridge1/RESULT","payload":"{\"Time\":\"2020-08-12T21:32:18\",\"RfReceived\":{\"Sync\":13080,\"Low\":420,\"High\":1270,\"Data\":\"DD80F2\",\"RfKey\":\"None\"}}","qos":0,"retain":false,"_msgid":"ae7c74e7.0c06a8"}`

![data](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a1f4be1ced0795d64bce4b9463762bfc294efd6.jpeg)

---

<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:** [12 August 2020 21:35 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/5 "2020-08-12T21:35:56Z")

</div>

Your payload is a string. Either feed it through a JSON node or set your mqtt in node to automatically parse JSON strings. Then you can simply copy the path to the item of interest from the debug window copy path button.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [12 August 2020 21:40 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/6 "2020-08-12T21:40:06Z")

</div>

> [@zenofmud](#):
>
> msg.RfReceived.Data

Thanks- that was it.  
What was the giveaway? That everything was quoted?

---

<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:** [12 August 2020 21:44 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/7 "2020-08-12T21:44:06Z")

</div>

> [@SteveMann](#):
>
> What was the giveaway? That everything was quoted?

That & the fact it looks like JSON and it wasn't an expandable object and lastly, it was coloured as strings are in the debug node.

In future, if unsure, you can do this in a function node...

```auto
node.warn(typeof msg.payload)
return msg;

```

It will output "string".

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [12 August 2020 22:30 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/8 "2020-08-12T22:30:21Z")

</div>

Thanks- both good tips.

---

<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:** [26 August 2020 22:30 UTC](https://discourse.nodered.org/t/json-question-get-one-value/31499/9 "2020-08-26T22:30:26Z")

</div>

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