# Extract values from complex payload

**URL:** https://discourse.nodered.org/t/extract-values-from-complex-payload/31866
**Category:** General
**Created:** [22 August 2020 06:33 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866 "2020-08-22T06:33:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anakaine](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anakaine](https://discourse.nodered.org/u/anakaine)
#### Post date: [22 August 2020 06:33 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866/1 "2020-08-22T06:33:51Z")

</div>

I'm a relative newbie to Node-Red, but capable developer in some other languages. What would be the best way to approach extracting the Temprature and Humidity values from the following payload?

The payload is being recieved over MQTT with AEDIS.

```auto
{"app_id":"testlorawandraginonode","dev_id":"mydevid,"hardware_serial":"00A1B2C3D4E5C6","port":1,"counter":21,"payload_raw":"EnCrYpT3d","payload_fields":{"Humidity":25,"Temperature":23.4},"metadata":{"time":"2020-08-22T06:15:33.41123456789Z","frequency":923.4,"modulation":"LORA","data_rate":"SF7BW125","airtime":56576000,"coding_rate":"4/5","gateways":[{"gtw_id":"eui-00800000a01234c6","timestamp":2370682735,"time":"2020-08-22T06:15:33.123456Z","channel":1,"rssi":-119,"snr":-1.2,"rf_chain":0,"latitude":-27.31055,"longitude":152.99,"altitude":15}]}}

```

---

<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 2020 06:47 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866/2 "2020-08-22T06:47:18Z")

</div>

Hi, firstly, I edited your post to correctly format code (it was being corrupted by forum formatting as you used "quote" button not the "code" `</>` button 🙂

Not to be too presumptuous but I guess you are not familiar with JSON?

So a small lesson on JS objects and their equivalent string representation (AKA JSON)...

_Your `payload` is a string/JSON (due to the `Output` setting on the MQTT node). You could attempt some complex splits and loops etc - but - as it is JSON (JavaScript Object Notation) - just let JS do its thing - turn that JSON back into a JS Object! (if you dont know what I mean, it'd be worth reading up - will help you greatly in node-red knowing the difference)_

So first off, change your MQTT IN to...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96825f9eb1741931963016f09832e3b7772c069c.png)  
... once you have turned the JSON back into an object, you will be able to simply "copy path" to any item in the object on the debug sidebar  
 ![P4lNSokZZp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59555cbcf431aaf83c9dbc59ce9d1a3c36ddefb7.gif)

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

### HOWEVER...

The data you posted is not quite valid JSON (missing `"` after `"dev_id":"mydevid`)

Do you have control over what is generating this bad JSON? If so, i recommend fixing this at the src - it will make your life soo much easier. The alternative is probably a regex or string parsing (not pretty and not necessary if JSON is correctly formatted)

or perhaps this was simply a copy/paste error?

* * *

Hope that helps.

---

<div class="post-metadata">

### Author: ![anakaine](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anakaine](https://discourse.nodered.org/u/anakaine)
#### Post date: [22 August 2020 06:53 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866/3 "2020-08-22T06:53:11Z")

</div>

@Steve-Mcl,

That is hands down the best reply I have ever had to a question I've posted. Thank you for being excellent!.

Showing the JSON path is actually a really great feature too.

I'll keep plugging away. I think that's exactly what I needed to get going. Thank you.

---

<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 2020 06:55 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866/4 "2020-08-22T06:55:21Z")

</div>

> [@anakaine](#):
>
> Thank you for being excellent!.

Haha - excellent response 😃 .

You're welcome.

Happy learning 👍

---

<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 October 2020 06:55 UTC](https://discourse.nodered.org/t/extract-values-from-complex-payload/31866/5 "2020-10-21T06:55:21Z")

</div>

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