# Looking for help with referencing object values

**URL:** <https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096>\
**Category:** General\
**Created:** [13 January 2021 21:51 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096 "2021-01-13T21:51:41Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [13 January 2021 21:51 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/1 "2021-01-13T21:51:42Z")

</div>

Hi, am very new to node-red and js .. getting the following from an mqtt input and trying to access the valuse in a js function to create an sql statment to post them into sqlite database with the same field names.

```auto
{"time":"2021-01-13 16:47:39","model":"SwitchDoc Labs FT020T AIO","device":12,"id":0,"batterylow":0,"avewindspeed":10,"gustwindspeed":20,"winddirection":272,"cumulativerain":27,"temperature":717,"humidity":97,"light":206,"uv":1,"mic":"CRC"}

```

Thank you for your time and trouble

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 January 2021 21:57 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/2 "2021-01-13T21:57:32Z")

</div>

Hi Ben.

When posting stuff like that, please use the `</>` button.

Which values to you want to access?

From where did you get this? A `debug` node?

(Edit or re-post the message and it may be easier to see too.)

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [13 January 2021 22:09 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/3 "2021-01-13T22:09:25Z")

</div>

I think I did use the \</\> .. but any way yes it is from a debug node on the output of my mqtt node.

---

<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:** [13 January 2021 22:16 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/4 "2021-01-13T22:16:16Z")

</div>

Hi @BenMtl

this page in the docs explains how you can use the Debug sidebar to identify the path to any message element: [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

It also helps you understand if `msg.payload` is a JSON String (where you can't directly access the individual properties inside it) or if it has already been parsed to a JavaScript Object where you can access its contents.

Worth a read through to see how that can help you understand what you've got.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 January 2021 22:20 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/5 "2021-01-13T22:20:07Z")

</div>

Ok. Something didn't work then.

It should look a whole lot different that what is shown.

Try this:

To the left of the `1` key is the key which I can't show here. It is basically very similar to '  
Press it `3` times. Press enter. Paste the stuff. Press enter. Press the afore mentioned key again 3 times.

Then it should be ok.

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [13 January 2021 22:31 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/6 "2021-01-13T22:31:26Z")

</div>

thanks I will check it again and see if I missed something.

---

<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:** [14 January 2021 10:10 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/7 "2021-01-14T10:10:25Z")

</div>

I have corrected the post format. Somehow you had two lots of backticks round it, but also an extra single backtick at the start and end of the flow.

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 13:59 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/8 "2021-01-14T13:59:06Z")

</div>

Thanks Colin

---

<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:** [14 January 2021 15:19 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/9 "2021-01-14T15:19:36Z")

</div>

How are you getting on with the docs pointed to earlier by Nick?

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 15:40 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/10 "2021-01-14T15:40:38Z")

</div>

going to sit down with it again in about 20 minutes. it shouldn't be that hard to pull the values from the key:value pairs to write to an db ..

---

<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:** [14 January 2021 16:21 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/11 "2021-01-14T16:21:41Z")

</div>

Have a play with the Template node (not ui-template). That provides a good way of building a query string from a number of variables. I am assuming you know the query string you are trying to build.

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 16:23 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/12 "2021-01-14T16:23:51Z")

</div>

yes very much so, just having an issue writing the js, to read the key values into the sql statment as values. was / am using the js function node .. had not thought about the template node.

---

<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:** [14 January 2021 16:40 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/13 "2021-01-14T16:40:10Z")

</div>

> [@BenMtl](#):
>
> had not thought about the template node.

It is often a good choice as it saves messing about with js. Feed the output into a debug node and get it working before connecting to the db.

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 16:45 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/14 "2021-01-14T16:45:02Z")

</div>

oh yes .. always debug first. Almost got my js function working .. right now it is giving me the key names not the values in my out put .. grrr so damn close

---

<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:** [14 January 2021 16:54 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/15 "2021-01-14T16:54:20Z")

</div>

Can I just check that you have a javascript object going into your function node and not a string?

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 16:57 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/16 "2021-01-14T16:57:21Z")

</div>

yes it is an object .. it is just how I am calling the values back I am sure ..

---

<div class="post-metadata">

**Author:** ![BenMtl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/benmtl/32/35281_2.png) [@BenMtl](https://discourse.nodered.org/u/BenMtl)\
**Post date:** [14 January 2021 18:04 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/17 "2021-01-14T18:04:04Z")

</div>

Thanks all .. took me a bit to figure out how to referance the key values in js. Got it .. I am now gathering the data to an sqlite database 🙂

---

<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:** [15 March 2021 18:04 UTC](https://discourse.nodered.org/t/looking-for-help-with-referencing-object-values/39096/18 "2021-03-15T18:04:06Z")

</div>

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